Jquery 创建iframe并在完成加载时侦听
我有一个函数,它创建了一个iframe,提供了一个zip文件供下载。 我希望在iframe完成加载后立即触发另一个函数,但我无法通过回显iframe src中的任何内容来实现这一点,因为该函数的php中有文件头。 我已经找到了监听load事件的说明,但似乎有些东西超出了我的理解范围:Jquery 创建iframe并在完成加载时侦听,jquery,iframe,listener,Jquery,Iframe,Listener,我有一个函数,它创建了一个iframe,提供了一个zip文件供下载。 我希望在iframe完成加载后立即触发另一个函数,但我无法通过回显iframe src中的任何内容来实现这一点,因为该函数的php中有文件头。 我已经找到了监听load事件的说明,但似乎有些东西超出了我的理解范围: function downloadZIP(structure) { ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "http:
function downloadZIP(structure) {
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", "http://www.example.com/<?=$work_folder?>/zip.php?structure="+structure+"&alpha=<?=$_GET['alpha']?>");
ifrm.style.width = 640+"px";
ifrm.style.height = 480+"px";
ifrm.style.display = "none";
document.body.appendChild(ifrm);
ifrm.onreadystatechange = function() {
if ( ifrm.readyState == 'complete' ) {
//iframeIsLoaded();
alert('loaded');
}
}
}
函数下载zip(结构){
ifrm=document.createElement(“IFRAME”);
ifrm.setAttribute(“src”http://www.example.com//zip.php?structure=“+结构+”&alpha=“”);
ifrm.style.width=640+“px”;
ifrm.style.height=480+“px”;
ifrm.style.display=“无”;
文件.body.appendChild(ifrm);
ifrm.onreadystatechange=函数(){
如果(ifrm.readyState=='complete'){
//iframeisload();
警报(“已加载”);
}
}
}
欢迎纯javascript或jquery建议。Parent.html
child.html
加载iframe(child.html
)中的文档时,它的最后一个功能将是调用父页面(parent.html
)上的iframeload()
)。当从子页面调用函数iframeload()
时,您可以放置回调或其他任何内容
另一种方法是在iframe本身上使用
onload事件处理程序
document.getElementById('ifrm')。onload=function(){
//把你的代码放在这里
}
有关iFrame的更多信息,请访问Parent.html
child.html
加载iframe(child.html
)中的文档时,它的最后一个功能将是调用父页面(parent.html
)上的iframeload()
)。当从子页面调用函数iframeload()
时,您可以放置回调或其他任何内容
另一种方法是在iframe本身上使用onload事件处理程序
document.getElementById('ifrm')。onload=function(){
//把你的代码放在这里
}
对于这一点以及更多有关iFrame的内容,请转到,您可以使用jquery。()
加载事件在元素和所有子元素都已加载时发送到元素
我的行李已经装满了。此事件可以发送到任何元素
与URL关联:图像、脚本、帧、iFrame和
窗口对象
您可以使用jquery。()
加载事件在元素和所有子元素都已加载时发送到元素
我的行李已经装满了。此事件可以发送到任何元素
与URL关联:图像、脚本、帧、iFrame和
窗口对象
function iframeLoaded() {
console.log("[[IFRAME LOADED]]");
}
window.onload = function() {
parent.iframeLoaded();
}
<script>
document.getElementById('ifrm').onload = function() {
// put your awesome code here
}
</script>
$('iframe').load(function(){
alert('loaded');
});