Jump to content

Changing Page From location.hash


jjacquay712

Recommended Posts

I am starting to see many web applications like gmail and facebook use the url hash to dynamically change the page.

 

Ex. http://mail.google.com/#inbox

 

How could you make an event handler call when ever the anchor changes? OnLoad doesn't work because it isn't called when the anchor changes. You can get the text of the anchor using location.hash.

 

            Thanks, John                               

 

Link to comment
https://forums.phpfreaks.com/topic/163441-changing-page-from-locationhash/
Share on other sites

I figured out how to do! You have to check or "poll" every set amount of time to see if location.hash is different then what is was last. Here is my code if anyone is interested:

 

 

var lasthash = "";

function init() { //Call when page loads
setInterval("checkHash()", 100);
}

function checkHash() {
if ( lasthash !== window.location.hash ) {
	lasthash = window.location.hash;
	ajaxNavigate(lasthash); //This function uses ajax to update the page
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.