2011-09-19 118 views
0

sample.htmlbeforeunload Safari浏览器IFRAME问题

<html> 
<head> 
<script type="text/javascript"> 
window.onbeforeunload = function (e) { 
    e = e || window.event; 

    // For IE and Firefox prior to version 4 
    if (e) { 
    e.returnValue = 'Any string'; 
    } 

    // For Safari 
    return 'Any string'; 
}; 

</script> 

</head> 
<body> 

<h1> <a href="http://www.yahoo.com"> Yahoo</a> </h1> 

</body> 
</html> 

main.html中

<html> 
<body> 

<iframe src="sample.html" width="100%" height="300"> 
    <p>Your browser does not support iframes.</p> 
</iframe> 

</body> 
</html> 

所以问题是,当我在雅虎的链接onbeforeunload功能点击是没有得到调用。

回答

0

,因为你没有带给出非常多的信息,我只能猜测什么是您的问题,并告诉你一个跨浏览器的卸载消息从here采取的工作可能性:

window.onbeforeunload = function (e) { 
    e = e || window.event; 

    // For IE and Firefox prior to version 4 
    if (e) { 
    e.returnValue = 'Any string'; 
    } 

    // For Safari 
    return 'Any string'; 
}; 

如果你做一些不同的事情,试试这个 - 如果它不适用,请添加一些代码。你应该怎么知道你的代码有什么问题而没有看到它?

+0

我已经提供了代码和更多信息供您参考。请看看.. – Abhimanyu

1

这是I帧

溶液我在iFrameObject可变的iFrame对象然后使用下面的命令它在Safari 3.1.1工作和其他浏览器太

iframeObject.contentWindow.onbeforeunload = confirmExit;