Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts

    body onload to anchor?

    this question should be simple enough to answer.

    i have this link

    Code:
    <a href="javascript:history.back()">Back</a>
    on the page that the user is going back to, i want it to go back to a specific anchor (or to the top of the page.... the anchor is at the top )
    - also the user can only get to the page with the <a href="javascript:history.back()"... link on it from one place.

    point being, how do i get the page to load to at a specific anchor?

    knowing that the page this link takes them to has an anchor called "top"
    do i do:
    Code:
    <a href="javascript:history.back()#top">Back</a>
    or do i put something on the page that the page being loaded like
    Code:
    <body onload="#top">
    lemme know :P
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well you could always do-
    Code:
    <body onload="window.scrollTo(0,0)">
    I'm not sure if just #top will work in onload, perhaps you might need-
    Code:
    location='#top';
    Of course you're using id's for the anchor aren't you ..
    Omnis mico antequam dominus Spookster!

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not a JS guru by any means (I know random JS stuff without a clue about how to implement most stuff).

    Will just "location='top'" work?

    Maybe onload="window.location=window.location + '#top'" ?

    Just make sure you have an ID'd or named (depending on what DTD you are using) anchor with a value of "top" at the top of the page. Actually, I can't remember if it needs to be on an anchor. It doesn't need to be an anchor in XHTML, but it might in HTML.

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    ummm, that's essentially what I said lol ..
    Omnis mico antequam dominus Spookster!

  • #5
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay. I was just "putting in my two cents". As I said, I'm no JS guru.

  • #6
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Haha fair enough..
    Omnis mico antequam dominus Spookster!

  • #7
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    i used the onload scrollto(0,0) and it works great, thanks.
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •