NOTE: I have now created a jQuery plugin which is my attempt of a solution to this issue. I am sure that it could be improved and i\'ve probably overlooked lots of use c
Great question. I actually handle this by using custom page load events. So in my core .js file I have a class like the following:
var Page = {
init: function(pageName) {
switch (pageName)
{
case: 'home': {
// Run home page specific code
}
case: 'about': {
// Run about page specific code
}
...
}
}
}
You can call this a bunch of ways, either in a page-specific $(document).ready()
or from the core script using some kind of URL parser (literally anything is possible with a URL parser):
$(document).ready(function() {
// http://www.mydomain.com/about
var currentPage = window.location.pathname; // "about"
Page.init(currentPage);
});
window.location
DOM reference: https://developer.mozilla.org/en/DOM/window.location