CopyCode The Code is as follows: <! Doctype HTML>
<HTML>
<Head>
<Meta charset = "UTF-8">
<Title> IFRAME onload is executed twice in Chrome/opera </title>
</Head>
<Body>
<SCRIPT>
VaR IFR = Document. createelement ('iframe ');
IFR. onload = function () {alert (1 );};
Document. Body. insertbefore (IFR, document. Body. childnodes [0]);
IFR. src = 'HTTP: // www.baidu.com ';
</SCRIPT>
</Body>
</Html>
The solution is simple. Just change the code order: Create an IFRAME, add it to the body, and add the load event. All browsers are consistent.Copy codeThe Code is as follows: var IFR = Document. createelement ('iframe ');
Document. Body. insertbefore (IFR, document. Body. childnodes [0]);
IFR. src = 'HTTP: // www.baidu.com ';
IFR. onload = function () {alert (1 );};
In addition, the safari5 test is used. Without alert, it is always loading and can last for more than 30 s. Let's try it out?