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 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Advanced scripting: need help to make IE8 behave!

    Ok, for starters I'm not a beginner and my website is running under standards mode (not quirks).

    When my site loads I perform:

    Code:
    window.location.replace(window.location.href + "#encodedstuff");
    The effect being that no new history points are created and the very first history point now includes some encoded info in the hash.

    When the user closes and relaunches IE8 and then chooses "reopen last browsing session" I expect IE to make the request for the page including the hash value. It does NOT! It simply makes the request for the URL without the hash (and then adds the hash as the next history point).

    I need help figuring out why and if there is a way to accomplish this without needing to add a parameter to the location get request (which will cause my site to reload upon launch if this parameter is not already set... I don't want it doing that).

    Please note that the browser DOES behave if I copy the new URL, including the hash value and paste it into a new tab (closing the old tab). When I relaunch IE8 and reopen the previous session it does make the request with hash value and my site is able to get the required info out of the hash.

    It only fails for a tab that initially did not have a hash and my script performs the above location.replace.

    Solving this is critical for my application, so I seriously appreciate any help!

  • #2
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts
    btw, it works exactly as I expect it to in Firefox

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    And how does it behave in MSIE 7?? Same way? Or does it work there?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts


    one problem at a time, maybe? Although I just tried it in Chrome and it exhibited the same behavior as IE8.

    So maybe that's just something I can't control?

    I really want the user to have the same web page built when they reopen their browser session.

    The only other way would be for me to encode the info as a get request name-value parameter... as I said before this would mean that on initial load it would reload the site (do another get request to the server). I'd rather not have that round about but it would indeed function as I require.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Quote Originally Posted by Skychan View Post
    The only other way would be for me to encode the info as a get request name-value parameter... as I said before this would mean that on initial load it would reload the site (do another get request to the server).
    Ummm...are you sure?

    In ASP code, I have often done
    Code:
    foo.asp?where=xyz
    and then had my ASP code output the page as
    Code:
    <body onload="location.href='#xyz';">
    And the browser is smart enough to NOT cause a reload; it just jumps to the #xyz same as if the user clicked on a <a href="#xyz">.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well, you are doing location.href = ...

    I am doing location.replace(...).

    And yes, neither ways cause reloads. I said it would cause a reload if I add a get request param (eg: start url "http://mysite.com/" then I do:
    Code:
    window.location.replace(window.location.href + "?data=encodedstuff")
    <-- THIS will cause the page to reload)

    I can try your way... but don't I need to include the full URL and not JUST the hash value in that statement?

    Also, you guys can see my problem in action:
    http://5.latest.subtabs.appspot.com
    Just make sure you go to the Options page (in the Tools menu in top-right corner) and turn OFF "Browser History" and turn ON "Restore subtabs on startup".

  • #7
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm still having this problem. If you are interested in this problem, do you understand fully what is happening? You can follow my above instructions to see the problem in action.

  • #8
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I can't find a solution.

    The alternative, as I already mentioned, is to also change a non-hash aspect of the URL in the location.replace(). This works. It properly replaces the history point with the new URL, including the hash value added and it is remembered upon browser restart in both Chrome and IE.

    For example, instead of changing
    http://www.mysite.com/
    to
    http://www.mysite.com/#statestuff
    I change it to
    http://www.mysite.com/?site=loaded#statestuff
    where "?site=loaded" isn't even being used for anything. It is necessary to force it to remember the hash upon browser reload.

    The problem is that when you change non hash stuff in the URL you cause a GET request, or reload of the page, which technically isn't necessary. The site worked fine to simply run location.replace() and only change the URL by adding in the hash stuff and didn't cause a reload. For whatever reason, FF is the only browser that bothers to actually change the URL in the Browser's history state to include the hash stuff.

    I can live with the alternative solution, it just isn't the most ideal. I have to make the site more efficient by not doing unnecessary work since the page is going to reload anyways.


  •  

    Posting Permissions

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