动态创建iframe标签页并监控其加载成功(onload)的事件

<html>
<body onload = test()>
</body>
<script>

function test() {
var iframe = document.createElement('iframe');
iframe.id = 'testframe';
iframe.name = 'testframe';
iframe.src = 'http://www.baidu.com/';
var fn = function() { alert('iframe loaded ok'); };
if (iframe.attachEvent) {
	iframe.attachEvent('onload', fn);
} else {
	iframe.onload = fn;
}
document.body.insertBefore(iframe, document.body.firstChild);
}
</script>

</html>
发布了7153 篇原创文章 · 获赞 654 · 访问量 122万+

猜你喜欢

转载自blog.csdn.net/i042416/article/details/104952130
今日推荐