<!DOCTYPE html> <html> <head> <title>Hash Change Example</title> <script type="text/javascript" src="EventUtil.js"></script> </head> <body> <p>Click each of these links to change the URL hash.</p> <ul> <li><a href="#up">Up</a></li> <li><a href="#down">Down</a></li> </ul> <p>This example only works in browsers that <code>onhashchange</code>.</p> <script type="text/javascript"> EventUtil.addHandler(window, "hashchange", function(event){ alert("Old URL: " + event.oldURL + " New URL: " + event.newURL); });
$(function(){
var hashValue = location.hash.slice(1);
if(hashValue) {
$(window).trigger("hashchange");
}
}); </script> </body> </html>
hashchange事件支持 IE8 FF3.6 chrome opera
event.oldURL, newURL 只有FF6, chrome opera