Jump to content

jquery hashchange reload?


rockinaway

Recommended Posts

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');

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.