2016-07-27 89 views
0

我的页面上有iframe中的页面(具有不同的域)。但iframed页有这个代码iframe中的JS反onbeforeunload提示

<script language="JavaScript"> 
window.onbeforeunload = confirmExit; 
function confirmExit() { 
    return "You have attempted to leave this page. Are you sure?"; 
} 
</script> 

所以我不能关闭父页面没有“你有企图...”的提示。这是非常恼人的提示,任何人都有想法如何阻止这种提示?

编辑:我忘了 - JS在儿童(iframed)页非常重要。我不能使用没有JS或表单的使用沙盒模式。

回答

0

这是可能的。您需要在父onbeforeunload事件中清理整个父页面。这会在调用之前删除带有onbeforeunload事件的子iframe。 在你的父页面添加以下代码:

<script language="JavaScript"> 
window.onbeforeunload = cleanPage; 
function cleanPage() { 
    document.write(""); 
} 
</script> 
0

由于它是一个跨源请求,因此无法访问页面的DOM以除去事件处理程序。

最接近你可能会阻止全部根据this other Stackoverflow question在框架内运行的JavaScript。

+0

对不起,我忘了 - JS在孩子(的iframe)页面是非常重要的。 –

+0

@MilanObrtlík - 然后,正如我在答案中所说的那样,你不能。 – Quentin