Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Jump to a Named Anchor

Options
  • 12-07-2008 3:10pm
    #1
    Registered Users Posts: 15,065 ✭✭✭✭


    I am doing some maintenance on a Web application at the moment. One of the admin screens allows the user to select calendar months by clicking hyperlinks. Each of the calendar hyperlinks reloads the page when clicked, the URL format is like this: page.aspx?month=2&year=2008 e.g. the data for February 2008 is to be viewed.

    The issue I have is that I would like the page to scroll to the location where the data is when it is reloaded rather than just going to the top of the page which it does by default. To use Boards as an example, all of the links on the front page bring you to the newest post when they are clicked. I have tried adding a named anchor into the admin screen but that doesn't seem to work when the URL contains parameters e.g. page.aspx#anchor works but page.aspx#anchor?month=2&year=2008 won't work :(.

    I've tried searching online but all I seem to get are pages telling me how named anchors work, no one seems to use named anchors along with a query string. Does anyone have any idea?


Comments

  • Registered Users Posts: 3,594 ✭✭✭forbairt


    dump your # at the end of the url

    index.aspx?bob=1&lhappy=2#link


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    Thanks forbairt, that's exactly what I needed! For anyone else that may read this in the future:
    • Works: page.aspx#anchor
    • Fails: page.aspx#anchor?month=2&year=2008
    • Works: page.aspx?month=2&year=2008#anchor

    This is all assuming page.aspx contains a named anchor in the form <a name="anchor"></a> or <a name="anchor" />.


  • Registered Users Posts: 9,194 ✭✭✭RobertFoster


    You don't necessarily need to use the <a name="x"></a> tags anymore. Any tags with an ID can be used as anchors and linked to. For example: http://www.rte.ie/#player


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    Thanks Robert, you are correct. I just tried that using the id of an ASP.NET Label control instead of the named anchor and it worked the same.

    For clarity with this application I will keep the named anchors but in future I think I will use the ids of server controls if appropriate.


Advertisement