View Full Version : Advanced scripting: need help to make IE8 behave!

06-23-2010, 04:10 AM
Ok, for starters I'm not a beginner and my website is running under standards mode (not quirks).

When my site loads I perform:

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!

06-23-2010, 04:12 AM
btw, it works exactly as I expect it to in Firefox

Old Pedant
06-23-2010, 04:19 AM
And how does it behave in MSIE 7?? Same way? Or does it work there?

06-23-2010, 04:26 AM

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.

Old Pedant
06-23-2010, 04:42 AM
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


and then had my ASP code output the page as

<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">.

06-23-2010, 04:52 AM
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:
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:
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".

10-06-2010, 02:29 AM
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.

10-06-2010, 10:09 PM
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
I change it to
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.