[英]'beforeunload' event only fires in firefox when I click on the page
I open a new window using window.open() 我使用window.open()打开一个新窗口
And then I am trying to run some script(an ajax call) when user closes the opened window. 然后,当用户关闭打开的窗口时,我尝试运行一些脚本(ajax调用)。
The open works fine,but the code doesn't work as expected in FF when I try to close the window 可以正常打开,但是当我尝试关闭窗口时,代码无法按预期运行在FF中
Here is my code 这是我的代码
<?php
echo '<div id="iframecontainer"><iframe name="meeting-iframe" frameborder="0" style="width:80%;height:80%" src="' . $link . '"></iframe></div>';
?>
<script>
(function ($) {
$(document).ready(function() {
// Variables from php
var event_id = '<?php echo $event_id; ?>';
var user_id = '<?php echo $current_user->uid; ?>';
//////////////////////////////////////////////////////////////////////
// Run function before window is closed,doesn't work as expected in FF
window.addEventListener("beforeunload", function (e) {
var e = e || window.event;
var message = 'Are you sure you want to leave the meeting?';
if(e) {
e.returnValue = message;
}
// Post to get meeting info
$.post('/easymeet/getInfo/' + event_id).done(function(meetResponse) {
//ajax callback ,I have hidden the code here as I don't think its relevent to the question
});
});
});
}(jQuery))
I am loading an iframe inside my window and the page the iframe is fetching is all flash(just to point out). 我正在窗口中加载iframe,iframe正在获取的页面都是Flash(仅供参考)。
I am testing in IE,chrome and Firefox Whats happening here is beforeunload is triggered and works well in IE and Chrome. 我正在IE,chrome和Firefox中进行测试这里发生的事情是触发卸载之前,并且在IE和Chrome中运行良好。
But in Firefox I manually have to click on the HTML or do some interaction. 但是在Firefox中,我必须手动 单击 HTML或进行一些交互。 If I try to close the window without doing anything, the 'beforeunload' event doesn't seem to fire at all.
如果我尝试不做任何事情而关闭窗口,则“ beforeunload”事件似乎根本不会触发。
Firefox has some configurations that you can find writing "about:config" in the navigation toolbar. Firefox具有一些配置,您可以在导航工具栏中找到编写“ about:config”的信息。 There you'll find some flags, including dom.require_user_interaction_for_beforeunload that makes 'beforeunload' event fires only when you click on the page.
在这里,您会发现一些标志,包括dom.require_user_interaction_for_beforeunload ,这些标志仅在您单击页面时才会触发“ beforeunload”事件。 But you can't modify this configuration through code;
但是您不能通过代码修改此配置。 You have to do this manually in Firefox.
您必须在Firefox中手动执行此操作。
PS: sorry for my english. PS:对不起,我的英语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.