rockinaway Posted December 6, 2011 Share Posted December 6, 2011 Well, I have basic hashchange functionality working where clicking different links will change the content of a page dynamically and will change the hash. HOWEVER, I want to be able to reload the content of the page when a link with the same hash is clicked. So, if I have a link producing the hash #idea. If this page is already loaded and I click the same link again (i.e. the hash doesn't change). Any ideas how i'd do this? I'm currently using this basic method: $("#link").click(function() { window.location.hash = "#i=link"; }); $(window).bind( 'hashchange', function(e) { // ajax request }) // Trigger the event $(window).trigger('hashchange'); Quote Link to comment https://forums.phpfreaks.com/topic/252609-jquery-hashchange-reload/ Share on other sites More sharing options...
rockinaway Posted December 6, 2011 Author Share Posted December 6, 2011 A work around I have done for now is: $("#link").click(function() { window.location.hash = ""; window.location.hash = "#i=link"; }); But this isn't ideal.. Quote Link to comment https://forums.phpfreaks.com/topic/252609-jquery-hashchange-reload/#findComment-1295059 Share on other sites More sharing options...
haku Posted December 8, 2011 Share Posted December 8, 2011 Are you trying to save the state so that the browser back button works with ajax calls? If so, then you may want to look at the new javascript functions that all browsers except IE implement: window.onpopstate() and history.pushState() These allow you to integrate AJAX applications with the browser button, using proper URLs, and not messing with hash states. You can see an example that I've developed on http://www.englishfriendjapan.com Quote Link to comment https://forums.phpfreaks.com/topic/252609-jquery-hashchange-reload/#findComment-1295642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.