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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts

    window.location.hash

    Hi,

    If you use inline JavaScript to forward a page to a new hash e.g:
    window.location.hash = 'action=test'; The onhashchange even doesn't fire.

    This is a good thing, because it means you can set up an initial hash representing the AJAX state. However the back button would take you from
    http://example.com/#action=test to http://example.com/

    Which creates a usability problem as the back button then has to be pressed twice to actually go back.

    SOMEHOW Google manage to avoid this. To see, open docs.google.com in a new window or tab and you will be taken to http://docs.google.com/#all
    And yet the back button is disabled - as if the transition to #all never even happened.

    Does anybody know how they do this? As it would solve the double back button problem I mentioned above.

    (This doesn't appear to be a serverside redirect as the hash appears once the page has loaded).
    Last edited by tribalmaniac; 07-05-2010 at 04:20 PM.

  • #2
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    maybe htaccess solves this.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Mmmm, I'm not so sure. Do you see the hash appearing once the page has loaded - and yet the back button is still disabled.
    Last edited by tribalmaniac; 07-05-2010 at 03:50 PM.

  • #4
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    as long as the document is open in a new tab, the back button is disabled, no wonder...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    I don't think you understand, Google, and the code I mention both forward the browser to a new hash.
    (I only mention opening a new window so you can see the effect.)

    In my case this enabled the back button as in my first example.
    However, Google's case - the back button does not become enabled.
    Last edited by tribalmaniac; 07-05-2010 at 04:10 PM.

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    I found a post regarding the same problem:

    http://bytes.com/topic/javascript/an...adding-history

    The solution is to use window.location.replace initially and window.location.hash thereafter.
    Last edited by tribalmaniac; 07-06-2010 at 11:04 AM.


  •  

    Posting Permissions

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