0

I have used the following function in my javascript code:

  function k_addLoadEvent() {
     var oldonload = window.onload;
     if (typeof window.onload != 'function') {
       alert('in');
       window.onload = function(){alert('hi');}
     } else {
       window.onload = function() {
         if (oldonload) {
           oldonload();
         }
         someFunction();
       }
     }
  }   
  k_addLoadEvent();

The line window.onload = function(){alert('hi');} is not working in IE 9 and below. The alert alert('in') is working but not the alert('hi'). I do not see any error in the console.

What am I missing in the code?

Akanksha
  • 188
  • 1
  • 13
  • 1
    Nothing? I see both alerts in IE 9. Perhaps security settings are preventing local files from running scripts. – RobG Feb 14 '14 at 04:59
  • Is it possible that something else in the javascript code might be causing it? – Akanksha Feb 14 '14 at 05:12
  • Where do you put your code? This matters. Try to put your code within body. Test this fiddle (http://jsfiddle.net/b58A4/). Then try to run it again with "onLoad" selected (select "onLoad" from the second drop down list in the upper left corner). – Johnny Feb 14 '14 at 05:46
  • it is working on ie9 from here @RobG : but strangewise he is able to see the first alert, so I guess this cannot be the reason? – xhallix Feb 14 '14 at 08:15
  • Possible duplicate of [jQuery throws SCRIPT5022: HierarchyRequestError when attempted to append a jQuery object on Internet Explorer ( IE)](http://stackoverflow.com/questions/23071968/jquery-throws-script5022-hierarchyrequesterror-when-attempted-to-append-a-jquer) – Jamie Counsell May 10 '17 at 16:18

0 Answers0