How can jQuery detect changes to a url?
For example: If a user goes to a page site.com/faq/ nothing shows, but if he goes to site.com/faq/#open
You can use the hashchange event.
function hashchanged(){
var hash = location.hash.replace( /^#/, '' );
//your code
}
window.addEventListener("hashchange", hashchanged, false);
or integrate a jquery hashchange plugin
$(function(){
// Bind the event.
$(window).hashchange(hashchanged);
// Trigger the event (useful on page load).
hashchanged();
});
function hashchanged(){
var hash = location.hash.replace( /^#/, '' );
//your code
}