[英]dynamically set iframe src
I have a program which will dynamically set an iframe src to load pages.我有一个程序可以动态设置 iframe src 来加载页面。 I need to hook a event handler for the page completely loaded.我需要为完全加载的页面挂钩一个事件处理程序。 How can i do it?我该怎么做? Thanks!谢谢!
<script type="text/javascript">
function iframeDidLoad() {
alert('Done');
}
function newSite() {
var sites = ['http://getprismatic.com',
'http://gizmodo.com/',
'http://lifehacker.com/']
document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)];
}
</script>
<input type="button" value="Change site" onClick="newSite()" />
<iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe>
Example at http://jsfiddle.net/MALuP/示例在http://jsfiddle.net/MALuP/
尝试这个:
top.document.getElementById('AppFrame').setAttribute("src",fullPath);
Try this...尝试这个...
function urlChange(url) {
var site = url+'?toolbar=0&navpanes=0&scrollbar=0';
document.getElementById('iFrameName').src = site;
}
<a href="javascript:void(0);" onClick="urlChange('www.mypdf.com/test.pdf')">TEST </a>
You should also consider that in some Opera versions onload is fired several times and add some hooks:您还应该考虑到在某些 Opera 版本中 onload 会被多次触发并添加一些钩子:
// fixing Opera 9.26, 10.00
if (doc.readyState && doc.readyState != 'complete') {
// Opera fires load event multiple times
// Even when the DOM is not ready yet
// this fix should not affect other browsers
return;
}
// fixing Opera 9.64
if (doc.body && doc.body.innerHTML == "false") {
// In Opera 9.64 event was fired second time
// when body.innerHTML changed from false
// to server response approx. after 1 sec
return;
}
Code borrowed from Ajax Upload从Ajax Upload 中借用的代码
try this code.试试这个代码。 then 'formId' div can set the image.然后'formId' div 可以设置图像。
$('#formId').append('<iframe style="width: 100%;height: 500px" src="/document_path/name.jpg"' +
'title="description"> </iframe> ');
Try this:尝试这个:
document.frames["myiframe"].onload = function(){
alert("Hello World");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.