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
WBOYOriginal
2016-05-16 18:51:011413browse
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;
Statement:
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