View Full Version : named anchors, back/foward and window.location in IE

09-02-2008, 08:17 AM

if i use an interval to poll window.location properties (href, hash or search), both IE and FF give accurate returns initially.

using named anchors, the poll returns accurately in both.

HOWEVER, if i navigate amongst the anchors and then use back/forward buttons - the address bar updates appropriately in both browsers, and the poll returns correctly in FF, but in IE it gives only the url of the last anchor manually clicked.


function update(){
document.getElementById("statustext").value = window.location.href;
window.onload = function(){
<input id="statustext" />
<a href="#1">1</a>
<a href="#2">2</a>
<a href="#3">3</a>
<a name="1"></a>
<a name="2"></a>
<a name="3"></a>

everything works fine EXCEPT in IE when back/forward buttons are clicked. the status won't change. in FF it works fine.

is there a workaround?


09-03-2008, 07:05 AM

09-04-2008, 05:20 AM
Well, got some good news for you: HTML5 specs a new event, hashchange that is fired when the fragment identifier is changed but the page otherwise remains the same. This feature was introduced by Microsoft in an ie8b1. See HTML5 5.9.9 History Traversal (http://www.w3.org/html/wg/html5/#history1), point 6:
If the specified entry has a URL that differs from the current entry's only by its fragment identifier, and the two share the same Document object, then fire a simple event with the name hashchange at the body element, and, if the new URL has a fragment identifier, scroll to the fragment identifier.And: Internet Explorer 8 Beta 1 Whitepapers: Better AJAX Development (http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=ie8whitepapers&ReleaseId=581)

I've read somewhere that one can use iframe elements in an elaborate fashion to make sure these are fragment identifier changes are inserted into the browsing history in earlier ie<8 though. I just don't know how, exactly, that is done, as that was not the topic of whatever blog post I saw it in. Google it, I know the answer must be out there somewhere.