jump to link in page in javascript generated HTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dark.peony@gmail.com

    jump to link in page in javascript generated HTML

    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!

  • Evertjan.

    #2
    Re: jump to link in page in javascript generated HTML

    wrote on 18 mrt 2006 in comp.lang.javas cript:
    [color=blue]
    > 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.[/color]

    Do you mean:

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

    ?
    [color=blue]
    > The source view of the page only shows the javascript methods.
    > The HTML is *not* visible in the source view.[/color]

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

    javascript:aler t((document.doc umentElement||d ocument.body).i nnerHTML)

    [color=blue]
    > Passing the "#ref" on the URL doesn't work.
    > Changing window.location to "ref" neither.
    >
    > Is this actually possible?[/color]

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

    [color=blue]
    > (--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...[/color]

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


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • dark.peony@gmail.com

      #3
      Re: jump to link in page in javascript generated HTML

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

      ======
      <script language="javas cript" type="text/javascript">
      objTreeMenu_1 = new TreeMenu("image s", "objTreeMenu_1" , "_self",
      "treeMenuDefaul t", true, false);
      newNode = objTreeMenu_1.a ddItem(new TreeNode('First level<a
      href=ct></a>', 'folder.gif', null, true, true, '', '',
      'folder-expanded.gif')) ;
      newNode.setEven t('onexpand', 'alert(\'Expand ed\')');
      newNode_1 = newNode.addItem (new TreeNode('Secon d level',
      'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif')) ;
      newNode_1_1 = newNode_1.addIt em(new TreeNode('Third level',
      'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif')) ;

      .......

      objTreeMenu_1.d rawMenu();
      objTreeMenu_1.w riteOutput();
      objTreeMenu_1.r esetBranches();

      </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.l ocation("ct")) doesn't work.

      Comment

      • VK

        #4
        Re: jump to link in page in javascript generated HTML


        dark.peony@gmai l.com wrote:[color=blue]
        > 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.l ocation("ct")) doesn't work.[/color]

        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.ht ml" to "siteMap.html#c t"

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

        Comment

        • dark.peony@gmail.com

          #5
          Re: jump to link in page in javascript generated HTML

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

          Comment

          • Evertjan.

            #6
            Re: jump to link in page in javascript generated HTML

            wrote on 18 mrt 2006 in comp.lang.javas cript:
            [color=blue]
            > Thanks for the reply.[/color]

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


            If you want to post a followup via groups.google.c om, 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/googlegroupsrep ly/>
            [color=blue]
            > Here's my code, the javascript is generated
            > from the PHP module TreeMenu.php:
            >
            > ======
            > <script language="javas cript" type="text/javascript">[/color]

            language="javas cript" is no longer needed, leave it out!
            [color=blue]
            > objTreeMenu_1 = new TreeMenu("image s", "objTreeMenu_1" , "_self",
            > "treeMenuDefaul t", true, false);
            > newNode = objTreeMenu_1.a ddItem(new TreeNode('First level<a
            > href=ct></a>', 'folder.gif', null, true, true, '', '',
            > 'folder-expanded.gif')) ;
            > newNode.setEven t('onexpand', 'alert(\'Expand ed\')');
            > newNode_1 = newNode.addItem (new TreeNode('Secon d level',
            > 'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif')) ;
            > newNode_1_1 = newNode_1.addIt em(new TreeNode('Third level',
            > 'folder.gif', 'test.php', false, true, '', '', 'folder-expanded.gif')) ;
            >
            > .......
            >
            > objTreeMenu_1.d rawMenu();
            > objTreeMenu_1.w riteOutput();
            > objTreeMenu_1.r esetBranches();[/color]

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

            [color=blue]
            > </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.[/color]

            You cannot, unless you give it a name, as I told you before.
            [color=blue]
            > The page is printed as a treemenu. the drawmenu() function
            > corresponds to document.write( str).
            >
            > The onload(window.l ocation("ct")) doesn't work.[/color]

            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)

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: jump to link in page in javascript generated HTML

              VK wrote:
              [color=blue]
              > dark.peony@gmai l.com wrote:[color=green]
              >> 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.l ocation("ct")) doesn't work.[/color]
              >
              > You are confused about anchors and links.[/color]

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

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


              PointedEars

              Comment

              Working...