Solution,
1. Mozilla provides an undocumented function:
// for Mozilla browsers
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
2. For IE browser, you can use IE’s unique defer attribute:
Script blocks with defer attributes will be executed after the DOM is loaded.
Non-IE browsers will ignore defer and directly execute the script code. Therefore, you can have two methods to prevent non-IE browsers from executing this code for IE:
1. Conditional comments
2. Conditional editing
3. For Safari, here is a jQuery Solution:
if (/WebKit/ i.test(navigator.userAgent)) { // sniff
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
clearInterval(_timer );
init(); // call the onload handler
}
}, 10);
}
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