[removed]() is not firing with IE 8 in first shot

后端 未结 9 2163

I am trying to make my pages work correctly with IE 8, I found out from here: http://www.masykur.web.id/post/How-to-Make-Our-Website-to-be-Ready-for-IE8.aspx that, my page h

9条回答
  •  心在旅途
    2020-12-01 09:55

    This is a pretty old thread but I found a solution that might help others.

    I was adding a function to window.onload via a dynamically injected script (really to mimic an external script load for reasons which are not important in this context). As stated in this post, on the first load within IE8, the window.onload would not fire, but all subsequent calls would.

    I found out that if I put this in the HTML file as an internal script, it would work everytime:

    var windowOnload = window.onload || function() {};
    window.onload = function() { windowOnload(); };
    

    All the above code does is "initializes" IE8's window.onload unobtrusively. I suspect that IE8 fails to trigger window.onload the first time if it is called from an external script as the onload event isn't attached yet to window (or in tech terms, its typeof is undefined). It seems that the first time that's what IE8 is doing: attaching onload to window without executing it properly.

    The above code then becomes quite obvious: We are merely forcing IE8 to recognize the onload event. We don't care what gets executed, or what doesn't, so we simply make sure to pipe on through any existing window.onload code that is already defined (just as a precaution).

    It is important to have this as an internal script to the HTML (at least from my testing).

    Your HTML would thus look something like this (the relevant parts):

     
     
    

    From my testing, after clearing cache, and reloading the page, I have gotten window.onload to successfully trigger each time.

    I hope this helps.

提交回复
热议问题