复制代码 代码如下:
iframe的onload在chrome/opera中执行两次
解决方法很简单,改下代码顺序即可:创建iframe, 添加到body中,最后添加load事件。所有浏览器下将表现一致。
复制代码 代码如下:
var ifr = document.createelement('iframe');
document.body.insertbefore(ifr,document.body.childnodes[0]);
ifr.src = 'http://www.baidu.com';
ifr.onload = function(){alert(1);};
此外用safari5测试,没有alert,一直在载入中,能持续30s以上。大家试试看呢?