Reputation: 369
First of all I'm not interested of using some jquery plugin. I just want to know how did they achieve it so I can create a script like that.
On html5 history we use window.onpopstate
event to detect back/forward browser event. What I want is to create something like this so I can use the hash type of url for other browser that doesn't support html 5
something like this:
if(history.pushState){
//use html5 history event
window.onpopstate = function(event){that.__loadCurrentLink();};
}else{
//use the History event for other browser
window.historyEvent = function(event){that.__loadCurrentLink();};
}
Can you guys give some hint or anything so I will have the idea how to do this.
I'm just doing this for learning purposes and for the other people who want to know how to do this too. I hope some javascript monster can lead us the way.
Upvotes: 0
Views: 802
Reputation: 5380
There is no event that fires when a "hash change" occurs in IE7, better described in this question.
On - window.location.hash - change?
Since you aren't interested in a "jQuery solution" I recommend that you read the top part of the best answer for IE7.
Upvotes: 0
Reputation: 4821
Assign an event handler for the hashchange
event to window and use a setInterval
for older browsers to poll window.location.hash
every 100ms etc, so when hashchange isn't supported, you could get pretty much the up to date hash.
I'd also suggest writing your links, buttons, etc to call the function that checks the hash on mouseup, so that you'd be guaranteed almost no delay when you click on a link that changes the hash.
Hashchange support in browsers: caniuse.com
Upvotes: 3
Reputation: 1889
Many older browsers don't natively support a hash change event. I believe the way jQuery abstracts this functionality into their event listeners is by using a setInterval() to constantly poll for hash changes.
Upvotes: 0