Using code on specific pages
I'm trying to set up my external js file to use page routes, so certain functions will only execute and be called on page which they are routed to.
I have the route working when I need the code to work on only one page for example:
route.add('example.aspx', function () {
// code to execute on example.aspx
});
But I would like to have some blocks of code accessible on multiple pages. for example:
route.add('page-one.aspx', 'page-two.aspx', function() {
// code to execute on page-one.aspx and page-two.aspx
});
Here is the variable for creating the routes:
var route = {
_routes: {},
add: function (url, action) {
this._routes[url] = action;
},
run: function () {
jQuery.each(this._routes, function (pattern) {
if (location.href.match(pattern)) {
this();
}
});
}
}