jump to an anchor/bookmark

Discussion in 'Javascript' started by Rob, Jul 30, 2004.

  1. Rob

    Rob Guest

    Hello all,

    I have an anchor in my page like <a name-"phase_two"/>.
    When I load my page I call the function body_onload in the onload event of
    the body tag. Then I like to jump to this anchor/bookmark based on the value
    of an variable.

    pseudecode example:

    function body_onload(){
    if (phase==2){
    jump_to_anchor("phase_two");
    }

    if (phase==3){
    jump_to_anchor("phase_three");
    }
    }

    Can this be done and if yes how?

    Thanks in advance
    Rob
    Rob, Jul 30, 2004
    #1
    1. Advertising

  2. Rob wrote:

    > I have an anchor in my page like <a name-"phase_two"/>.
    > When I load my page I call the function body_onload in the onload event of
    > the body tag. Then I like to jump to this anchor/bookmark based on the value
    > of an variable.



    Check the location.hash property:
    <URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/hash.asp>

    window.onload=function(evt){
    var hashValue="#foo";
    if(location.hash!=hashValue)
    location.hash=hashValue;
    }


    HTH
    Yep.
    Yann-Erwan Perio, Jul 30, 2004
    #2
    1. Advertising

  3. Rob

    Rob Guest

    Thank a lot, exactly what I needed

    Rob
    "Yann-Erwan Perio" <> schreef in bericht
    news:410ab977$0$22940$...
    > Rob wrote:
    >
    > > I have an anchor in my page like <a name-"phase_two"/>.
    > > When I load my page I call the function body_onload in the onload event

    of
    > > the body tag. Then I like to jump to this anchor/bookmark based on the

    value
    > > of an variable.

    >
    >
    > Check the location.hash property:
    >

    <URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/ha
    sh.asp>
    >
    > window.onload=function(evt){
    > var hashValue="#foo";
    > if(location.hash!=hashValue)
    > location.hash=hashValue;
    > }
    >
    >
    > HTH
    > Yep.
    Rob, Jul 30, 2004
    #3
    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. Robert Wehofer

    How to jump to an anchor?

    Robert Wehofer, Nov 13, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,209
    John Carnahan
    Nov 17, 2003
  2. darrel
    Replies:
    16
    Views:
    13,364
    darrel
    Feb 8, 2005
  3. Aaron Freeman
    Replies:
    7
    Views:
    1,729
    Jonathan N. Little
    Mar 17, 2006
  4. Robert Mark Bram

    Jump to named anchor after form processing

    Robert Mark Bram, Oct 20, 2004, in forum: ASP General
    Replies:
    3
    Views:
    178
    Evertjan.
    Oct 21, 2004
  5. Eadwine Rose
    Replies:
    2
    Views:
    191
    Eadwine Rose
    Oct 15, 2006
Loading...

Share This Page