【发布时间】:2016-08-07 18:32:13
【问题描述】:
我使用 window.open() 打开一个新窗口
然后我试图在用户关闭打开的窗口时运行一些脚本(一个 ajax 调用)。
打开工作正常,但是当我尝试关闭窗口时,代码在 FF 中没有按预期工作
这是我的代码
<?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))
我正在我的窗口中加载一个 iframe,而 iframe 正在获取的页面全是 flash(只是指出)。
我正在 IE、chrome 和 Firefox 中进行测试 这里发生的是 beforeunload 被触发并且在 IE 和 Chrome 中运行良好。
但在 Firefox 中,我手动必须单击 HTML 或进行一些交互。如果我尝试关闭窗口而不做任何事情,'beforeunload' 事件似乎根本不会触发。
【问题讨论】:
-
有什么解决办法吗?
-
@IonicăBizău 你找到解决方案了吗?我抓挠我的头发
-
@slier 不,这只是 Firefox 的工作方式(除非您更改
about:config–– 如下所述––,您可能对此不感兴趣)。恐怕没有办法强制这样做。 -
@IonicăBizău 是的,我想是的 ..thx!
标签: javascript jquery html firefox iframe