Home > Web Front-end > JS Tutorial > Solution to the conflict between body onload and window.onload in the page_javascript skills

Solution to the conflict between body onload and window.onload in the page_javascript skills

WBOY
Release: 2016-05-16 18:51:01
Original
1409 people have browsed it
1. Use attachEvent to add the functions that need to be run to onload
Copy the code The code is as follows:

if (document.all)
{
window.attachEvent('onload', FuncName)
}
else
{
window.addEventListener('load ', FuncName, false);
}

2. Use window.onload = function(){FuncName1(); FuncName();} to directly onload the two functions. You can add a judgment,
Copy code The code is as follows:

var o = window.onload;
if ((typeof o)=='function')
window.onload = function(){o(); FuncName();}
else
window.onload = FuncName;
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