What is the best practice to not to override other bound functions to [removed]?

后端 未结 3 828
星月不相逢
星月不相逢 2021-01-03 23:36

How much I dig into JavaScript, I find myself asking that much. For example we have window.onresize event handler and if I say:

window.onresize          


        
3条回答
  •  一整个雨季
    2021-01-04 00:20

    Instead of replacing such a catch-all handler, you should just add a DOM 2 listener like this:

    window.addEventListener("resize", myResizeFunction);
    

    or in more details:

    if (window.addEventListener) {    // most non-IE browsers and IE9
       window.addEventListener("resize", myResizeFunction, false);
    } else if (window.attachEvent) {  // Internet Explorer 5 or above
       window.attachEvent("onresize", myResizeFunction);
    }
    

提交回复
热议问题