JavaScript event [removed] not triggered

后端 未结 8 1068
无人及你
无人及你 2021-02-01 01:15

I\'ve got the following code in a website:

 window.onload = resize;
 window.onresize = resize;

 function resize(){
  heightWithoutHeader = (window.innerHeight -         


        
8条回答
  •  星月不相逢
    2021-02-01 01:42

    I had this happen when I added 3rd party jQuery code we needed for a partner. I could have easily converted my antiquated window.onload to a jQuery document ready. That said, I wanted to know if there is a modern day, cross browser compatible solution.

    There IS!

    window.addEventListener ? 
    window.addEventListener("load",yourFunction,false) : 
    window.attachEvent && window.attachEvent("onload",yourFunction);
    

    Now that I know ... I can convert my code to use the jQuery route. And, I will ask our partner to refactor their code so they stop affecting sites.

    Source where I found the fix --> http://ckon.wordpress.com/2008/07/25/stop-using-windowonload-in-javascript/

提交回复
热议问题