欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iframe的onload在Chrome/Opera中執(zhí)行兩次Bug的解決方法

 更新時(shí)間:2011年03月17日 00:20:38   作者:  
創(chuàng)建iframe對象,添加load事件, 再將iframe添加到body中。Chrome/Opera中會(huì)造成load事件的handler執(zhí)行兩次。
復(fù)制代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>iframe的onload在Chrome/Opera中執(zhí)行兩次</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>

解決方法很簡單,改下代碼順序即可:創(chuàng)建iframe, 添加到body中,最后添加load事件。所有瀏覽器下將表現(xiàn)一致。
復(fù)制代碼 代碼如下:

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,一直在載入中,能持續(xù)30s以上。大家試試看呢?

相關(guān)文章

最新評(píng)論