June 4, 201313 yr Hey Guys, It's been a while. and I'm back with a new problem. Hopefully this time someone can help me.. My problem is that IE , FF and Opera don't scroll back to an anchor by pressing the back button. or using JS history.back(). Example: I am at www.website.com/#anchor1 and I will click a link that takes me to www.website.com/#anchor2 Then I press the back button of my browser. the URL changes to www.website.com/#anchor1 but the location of the window doesn't change to #anchor1. So, after searching for a while. ( 1 1/2 hours and counting) I can't find anything that helps. The problem occurs at www.4people.nl if you go to cases and click on any of the top 3 images. and then try to go back. It doesn't have to work with history back. I don't care how it works. as long as I can go back.. So maybe you know a solution or alternative? thanks
June 4, 201313 yr You could try a simple jQuery function to check the hash exists, something like this: $(document).ready(function() { if(window.location.hash) { var h = window.location.hash; window.location.hash = h; } });
June 4, 201313 yr Author Thanks Lindsey, that was very helpful. In the end this is what I came up with: $(document).ready(function() { $(".checkanchor").click(function(){ setTimeout(function(){ if(window.location.hash) { var h = window.location.hash; window.location.hash = h; } },500); }); });
June 4, 201313 yr Author seems like the code tags still bugs out text below it, and make editting posts a hell.Since it is a one-page design, loading it on document ready alone isn't enough. So I run the function when someone clicks on a link with the class checkanchor. Then I can into the problem that the browser would run the function before updating the URL. which is why I gave it a delay with setTimeout.
Create an account or sign in to comment