www.webdeveloper.com
Results 1 to 10 of 10

Thread: document.location.reload(false) fails to go to #anchor

  1. #1
    Join Date
    Jul 2011
    Posts
    9

    document.location.reload(false) fails to go to #anchor

    Code:
    <a name="loc"></a>
    <a href="#loc" onClick="document.location.href='#loc';document.location.reload(false);return false">Click here to go to your location</a>
    When you click onto the link you should go to the page location marked by the anchor tag "loc", however, upon clicking you go to the top of the page and never redirected to the exact spot where your anchor tag is located. Why is that? I'm using IE6 (per requirement) as my platform.

    Thanks

  2. #2
    Join Date
    May 2011
    Posts
    194

    maybe this


  3. #3
    Join Date
    Jul 2011
    Posts
    9
    I added "return false", to no avail, the results remained the same. I cannot go to my URL#anchor; it constantly goes to URL without the direction to the anchored spot on the URL

  4. #4
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    Code:
    <a name="loc"></a>
    <a href="javascript:return false" onClick="document.location.href='#loc';document.location.reload(false);return false">Click here to go to your location</a>

  5. #5
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by DanInMA View Post
    Code:
    <a name="loc"></a>
    <a href="javascript:return false" onClick="document.location.href='#loc';document.location.reload(false);return false">Click here to go to your location</a>
    Tried that as well, same wrong results: never goes to url#loc, just to url

  6. #6
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    Ok, I misunderstood. Does the following not work as well? This is the standard way to do it. The few times I've actually used it , it works fine in IE6.

    Code:
    <a name="loc"></a>
    <a href="#loc">Click here to go to your location</a>

  7. #7
    Join Date
    Jul 2011
    Posts
    9
    Believe it or not, it fails!

    However, I have found a rather strange pattern: it consistently fails whenever you try to access http://www.mydomain.com/registration.html?id=1#loc

    But it works perfectly if you go to http://www.mydomain.com/registration.html#loc

    Why does this occur?

  8. #8
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    that occurs because that is the way anchors are supposed to work.

    In my previous example, in some browsers if the anchor you are trying to move to is already on the screen somewhere, they may not scroll so it is at the top of the current view.

    there are plenty of scripts out there that will force ti to do so, it just depends on your needs.

  9. #9
    Join Date
    Jul 2011
    Posts
    9
    I tried using the following:

    Code:
    <a name="loc"></a>
    <a href="javascript:return false" onClick="document.location.hash='loc';document.location.reload(false);return false">Click here to go to the location</a>
    To no avail I even tried replacing document.location.hash with window.location.hash, again, to no avail. I've run out of ideas

  10. #10
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    Nope, i was wrong, it should be a name attribute.

    you shouldn't need JavaScript to do what you are trying to do. do you have a test page you can link? maybes it is happenign for another reason.

    -examples: http://www.echoecho.com/htmllinks08.htm
    Last edited by DanInMA; 08-09-2011 at 01:24 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles