Home > Web Front-end > JS Tutorial > Introduction to how to deal with multiple calls and infinite loop bugs in window.onresize under IE_javascript skills

Introduction to how to deal with multiple calls and infinite loop bugs in window.onresize under IE_javascript skills

WBOY
Release: 2016-05-16 17:16:05
Original
1056 people have browsed it

window.onresize has a bug in IE browser where it is executed multiple times or even loops endlessly, causing the browser to freeze

Solution:

Copy the code The code is as follows:

//Place the onresize event on the div under IE browser
if(navigator.userAgent && navigator.userAgent.toLowerCase().indexOf("msie")>-1){
document.body.innerHTML = '
' document.body.innerHTML;
} else {
window.onresize = function(){
resetClientWidth();
lazyLoadImgesMethod();
};
}

ps: FF browser does not support writing onresize events on divs. Although window.onresize will not loop endlessly under FF, if there is an alert execution in the function, FF browser will also It will freeze, which is a very helpless bug.

PS: navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie")>-1 This problem of judging IE will appear in the chrome browser" toLowerCase()" method undefined error.

So the correction is navigator.userAgent.toLowerCase().indexOf("msie")>-1

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template