views:

644

answers:

4

I have a site with anchor navigation (like gmail, when the anchor value changes a new content for a page is loaded with ajax). In Firefox, when I change the anchor (with js or with a page) a new item in the history is created and works perfectly. But in IE6 it doesn't stores this new item and the back button doesn't work as expected.

Is there anyway to add this new item using javascript? This is possible because gmail does it but I don't know how it does it.

A: 

I think you may have a different problem. IE6 certainly handles # links in history as it should for me on any given test page, so I believe either you have broken this in some way or you have a bug with your particular version of IE.

I suggest you try a few different copies and versions of IE6 on other machines to rule out the latter, and then try simplifying your code and rebuilding it to see if and when the problem appears. Turning off JS may (html depending) be a fast way to test this.

If all else fails I suggest you look at Really Simple History which (last time I checked) solves almost all JS/history problems you can throw at it.

annakata
A: 

Yahoo has a history manager too.

epascarello
I'm using jQuery. Is there any history manager for it?
+7  A: 

I've done a lot of work with history and using the hash. Almost all of the existing history plugins have some sort of gap in them. The one I've used that's pretty close to perfect is this one which is a jQuery plugin:

http://www.mikage.to/jquery/jquery.history.js

It was updated in March of this year handles IE 8 issues and it also deals with IE6 pretty successfully. One thing I've noticed is that IE really hates having ? in the hash after the #. It stops properly handling the hash when the ? is present. Even this one I think needs a little patch for the ?, I really need to send that along to Mikage. The way to handle this is instead of using location.hash in the plugin when referencing the hash, use this function:

function getHash(loc) {
    loc = loc.toString();
    if (loc.indexOf("#") != -1)
        return loc.substring(loc.indexOf("#"));
        else return "";
}

So in those spots where you need the hash, pass location the to function...

 getHash(location)

...instead of using location.href. But note that for IE, because it's using the iframe, you want to use iframe.location instead.

 getHash(iframe.location)

Yahoo's Bug

You can see that Yahoo doesn't gracefully handle ?'s in IE when looking at this URL:

http://developer.yahoo.com/yui/examples/history/history-tabview.html#tabview=tab1?7236471234

It should just ignore the non-existent module, (which it does for other names which have no ?'s in them). But it raises a JavaScript error when a ? is in the URL.

(I will extend this list in a moment)

Really Simply History

Frankly, it's primary issue seems to be it's gone dormant. I've experienced this issue and just didn't want to dig through it:

Also, even though no changes appear to take place on the page while I travel backward through the history, the back functionality will return once I hit the pages that I had been navigating before the one using RSH. So, if I clicked on four links in the RSH page, back functionality will return after I have clicked on the back button four times. I hope that makes sense.

altCognito
+1 for the gaps, but more importantly for the ? after #, that could easily be the killer here
annakata
I'd never heard of the '#?' issue before. Good to know.
Crescent Fresh
The funny thing is, I modeled my history function to work exactly like a URL and thought I was very clever. After wandering around looking at the different implementations and seeing if I had done well, I ran into facebook, which happens to use a very similar idea to track the history. Frankly, I should turn this into a more fleshed out plugin that is complete with the URL parser and make it event driven.
altCognito
Last year IE6 was patched with a bug that breaks all JS implementations on manual hash change (in the address bar)
Sergey Ilinsky
This jquery.history.js worked for me! But in IE6 you need to call it using the js function.
@alt: gmail does the trick you mention too. They store very readable 'urls' in their hashes.
Crescent Fresh
A: 

@altCognito - do you have a working example using your getHash function? I'm so close to getting it working but it just won't work in IE6 :( Any help much appreciated!

DC