JavaScript window.onload chaining


/ Published in: JavaScript
Save to your folder(s)

Window.onload chaining using Namespaces.


Copy this code and paste it in your HTML
  1. /* Run code inside a new namespace. This will allow the use of
  2.  * the same variable 'previous_onload', across multiple namespaces.
  3.  *
  4.  * Use the exact same code multiple times, and your functions
  5.  * will be executed in the order in which they were stacked. */
  6.  
  7. (function() {
  8.  
  9. // Backup previous onload method.
  10.  
  11. var previous_onload = window.onload;
  12.  
  13. window.onload = function() {
  14.  
  15. try { previous_onload(); } catch(e) { } // Execute. Ignore if error.
  16.  
  17. // Your code goes here
  18.  
  19. console.log("Running Code...");
  20.  
  21. }
  22.  
  23. })();

URL: http://paste.pocoo.org/show/378207/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.