Iframe加载和主站点 [英] Iframe loading and the main site
本文介绍了Iframe加载和主站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有以下代码:
Having following code
<iframe id="myframe" src="..."></iframe>
<script>
document.getElementById('myframe').onload = function() {
alert('myframe is loaded');
};
</script>
在脚本中分配onload处理程序之前,iframe是否可以完成加载?
Is it possible that the iframe finish loading before we assign onload handler in the script?
推荐答案
在这种情况下,使用javascript创建iFrame。像这样:
In this case, create the iFrame by using javascript. Something like this:
window.onload = function(){
var link = "https://www.w3schools.com/default.asp"
var iframe = document.createElement('iframe');
iframe.width="600px";
iframe.height="400px";
iframe.id="iframe1";
iframe.setAttribute("src", link);
document.getElementById('iframe1').onload = function() {
alert('myframe is loaded');
};
document.getElementById("maindiv").appendChild(iframe);
}
这可以解决您的问题。
这篇关于Iframe加载和主站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文