/ Published in: JavaScript
This will initialize page depending on body tag id. Will load global init code for all pages and specific initialization per page.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var nameSpace = { onload : function() { alert('global'); var page = document.body.id; if(this[page] && typeof this[page].onload === 'function') { this[page].onload(); } }, homepage : { onload : function(){ alert('home'); } }, contact : { onload : function(){ alert('contact'); // onload stuff for contact us page } } }; //Execute global init and specific to page $(document).ready( function(){ nameSpace.onload(); }); The HTML <html> <body id="homepage"> This is home </body> </html>