繁体   English   中英

如何仅针对 iframe 覆盖 windows.onbeforeunload 函数?

[英]How can i override the windows.onbeforeunload function only for an iframe?

我有一个事件监听器

window.onbeforeunload=function(evt){
//causes pop up 
}

我需要使用 iframe 的另一个事件侦听器覆盖它(在此处下载案例)。 下面的代码不起作用

var tIFrame = document.getElementById('Download');

iFrame.contentWindow.addEventListener('beforeunload', wrappedFn, false);

iFrame.addEventListener('beforeunload',wrappedFn,true);

感谢@Bergi 的提示。 下面的代码对我有用

var iFrame=document.getElementById('Download');
iFrame.contentWindow.onbeforeunload=function(){}
iFrame.contentWindow.location.href=sCmd;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM