Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Mario Wereka
Added: May 7, 2019 9:35 PM
Views: 15
Tags: no tags
  1. var bodyOnload = document.body.onload;
  2. window.onload = function() {
  3.   alert('window.onload')
  4.   bodyOnload()
  5. }
  6.  
  7. if (window.addEventListener) {
  8.   window.addEventListener('load', function() {
  9.     alert('addEventListener')
  10.   }, false);
  11. } else if (window.attachEvent) { // IE < 9
  12.   window.attachEvent('onload', function() {
  13.     alert('attachEvent')
  14.   });
  15. }
  16. <body onload="alert('body onload')">
  17.  
  18. </body>