jump to link in page in javascript generated HTML

D

dark.peony

Hi,

(--1--)

I'm trying to find a way to jump to a link (<a href="ref"></a>) in a
page
that is generated with javascript.

The source view of the page only shows the javascript methods.
The HTML is *not* visible in the source view.

Passing the "#ref" on the URL doesn't work.
Changing window.location to "ref" neither.

Is this actually possible?

(--2--)

The scrollTo(x,y) function with javascript generated HTML seems
also problematic with IE, not with Mozilla. Well I'm having probs
with scrollTo(x,y) on IE in all cases, even static HTML...

Thanks!
 
E

Evertjan.

wrote on 18 mrt 2006 in comp.lang.javascript:
Hi,

(--1--)

I'm trying to find a way to jump to a link (<a href="ref"></a>) in a
page
that is generated with javascript.

Do you mean:

<a name="ref"></a>

?
The source view of the page only shows the javascript methods.
The HTML is *not* visible in the source view.

Not relevant, you probably can see the code with this:

javascript:alert((document.documentElement||document.body).innerHTML)

Passing the "#ref" on the URL doesn't work.
Changing window.location to "ref" neither.

Is this actually possible?

What is "passing to"? Show us your code.

(--2--)

The scrollTo(x,y) function with javascript generated HTML seems
also problematic with IE, not with Mozilla. Well I'm having probs
with scrollTo(x,y) on IE in all cases, even static HTML...

Use body-onload, the page has to be ready first
 
D

dark.peony

Thanks for the reply. Here's my code, the javascript is generated
from the PHP module TreeMenu.php:

======
<script language="javascript" type="text/javascript">
objTreeMenu_1 = new TreeMenu("images", "objTreeMenu_1", "_self",
"treeMenuDefault", true, false);
newNode = objTreeMenu_1.addItem(new TreeNode('First level<a
href=ct></a>', 'folder.gif', null, true, true, '', '',
'folder-expanded.gif'));
newNode.setEvent('onexpand', 'alert(\'Expanded\')');
newNode_1 = newNode.addItem(new TreeNode('Second level',
'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif'));
newNode_1_1 = newNode_1.addItem(new TreeNode('Third level',
'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif'));

.......

objTreeMenu_1.drawMenu();
objTreeMenu_1.writeOutput();
objTreeMenu_1.resetBranches();

</script>

=========
somewhere in the code you see <a href="ct"></a>.
I'd like to jump to that when the page is shown in the browser.
The page is printed as a treemenu. the drawmenu() function
corresponds to document.write(str).

The onload(window.location("ct")) doesn't work.
 
V

VK

somewhere in the code you see <a href="ct"></a>.
I'd like to jump to that when the page is shown in the browser.
The page is printed as a treemenu. the drawmenu() function
corresponds to document.write(str).

The onload(window.location("ct")) doesn't work.

You are confused about anchors and links.
<a href="ct"></a> is not an anchor, it's a link. You cannot navigate to
it by HTML means. In order to make it both link and anchor, you need to
give it a name:

<a href="somePage.html" name="ct">Link and Anchor</a>

Now you can refer to this place on your page as ...href="#ct"...

And if your page is served anyway by PHP, it is easier to make
server-side redirect then, so the url would be changed from say
"siteMap.html" to "siteMap.html#ct"

This way the "jump" will be done even with JavaScript disabled.
 
D

dark.peony

Thanks a lot. With this little bit of elementary knowledge you ended a
stretch of 3 day frustration.
 
E

Evertjan.

wrote on 18 mrt 2006 in comp.lang.javascript:
Thanks for the reply.

Please quote what you are replying to.
This is NOT email!


If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the
article headers. said:
Here's my code, the javascript is generated
from the PHP module TreeMenu.php:

======
<script language="javascript" type="text/javascript">

language="javascript" is no longer needed, leave it out!
objTreeMenu_1 = new TreeMenu("images", "objTreeMenu_1", "_self",
"treeMenuDefault", true, false);
newNode = objTreeMenu_1.addItem(new TreeNode('First level<a
href=ct></a>', 'folder.gif', null, true, true, '', '',
'folder-expanded.gif'));
newNode.setEvent('onexpand', 'alert(\'Expanded\')');
newNode_1 = newNode.addItem(new TreeNode('Second level',
'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif'));
newNode_1_1 = newNode_1.addItem(new TreeNode('Third level',
'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif'));

.......

objTreeMenu_1.drawMenu();
objTreeMenu_1.writeOutput();
objTreeMenu_1.resetBranches();

This is all based on a library you do not show, so we cannot comment on
that.

</script>

=========
somewhere in the code you see <a href="ct"></a>.
I'd like to jump to that when the page is shown in the browser.

You cannot, unless you give it a name, as I told you before.
The page is printed as a treemenu. the drawmenu() function
corresponds to document.write(str).

The onload(window.location("ct")) doesn't work.

elementary, my dear unnamed.

Please try to learn some javascript. This NG is not a helpdesk for
correcting machine generated script. That is like asking a translator for
corrections to a bad machine translation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top