[英]SRC attributes in IFRAME change with onload function
if I have the "src" attributes in IFRAME change is the "onload" Function not executed. 如果我在IFRAME中具有“ src”属性,则更改为“ onload”功能未执行。 It works ONLY when first called.
仅在首次调用时有效。
JavaScript: JavaScript:
function dialog () {
document.getElementById('result').src = "myurl";
}
function loading() {
document.getElementById('loading').style.display = "none";
document.getElementById('result').style.display = "block";
}
HTML: HTML:
<div id="loading"><img src="loading.gif"/></div>
<iframe style="display:none;" id="result" onload="loading();" src="myurl"/></iframe>
Thank you! 谢谢!
Does your page domain and iframe domain the same? 您的网页域和iframe域是否相同? If they are different you can use CORS to access iframe events.
如果它们不同,则可以使用CORS访问iframe事件。
EDIT 编辑
<script>
function dialog() {
document.getElementById('result').src = "http://jsfiddle.net";
}
function loading() {
alert('Loading finished');
document.getElementById('loading').style.display = "none";
document.getElementById('result').style.display = "block";
}
</script>
<div id="loading">Loading</div>
<iframe style="display:none;" id="result" onload="loading();" src="http://jsfiddle.net"/>
It works, live demo -- http://jsfiddle.net/xf2LgLsg/ I believe you write JS after HTML, so this may be a problem. 可以运行,现场演示-http: //jsfiddle.net/xf2LgLsg/我相信您是在HTML之后编写JS的,所以这可能是个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.