jump to link in page in javascript generated HTML

Discussion in 'Javascript' started by dark.peony@gmail.com, Mar 18, 2006.

  1. Guest

    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!
     
    , Mar 18, 2006
    #1
    1. Advertising

  2. Evertjan. Guest

    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


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Mar 18, 2006
    #2
    1. Advertising

  3. Guest

    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.
     
    , Mar 18, 2006
    #3
  4. VK Guest

    wrote:
    > 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.
     
    VK, Mar 18, 2006
    #4
  5. Guest

    Thanks a lot. With this little bit of elementary knowledge you ended a
    stretch of 3 day frustration.
     
    , Mar 18, 2006
    #5
  6. Evertjan. Guest

    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. <http://www.safalra.com/special/googlegroupsreply/>

    > 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.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Mar 18, 2006
    #6
  7. VK wrote:

    > wrote:
    >> 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.


    Nonsense. Will you ever get informed properly before you post advice?

    <URL:http://www.w3.org/TR/html4/struct/links.html>


    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 20, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim
    Replies:
    3
    Views:
    16,118
    Ron & Beth
    Sep 16, 2003
  2. Galsaba

    How to do "Jump" (link?)

    Galsaba, Dec 2, 2003, in forum: HTML
    Replies:
    13
    Views:
    720
    Jukka K. Korpela
    Dec 7, 2003
  3. Raymond Schmit

    How to link/jump on a specific page

    Raymond Schmit, Apr 28, 2009, in forum: HTML
    Replies:
    7
    Views:
    667
    Jonathan N. Little
    Apr 30, 2009
  4. Eadwine Rose
    Replies:
    2
    Views:
    229
    Eadwine Rose
    Oct 15, 2006
  5. Replies:
    0
    Views:
    135
Loading...

Share This Page