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
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
}
}

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.