简体   繁体   English

当我单击页面时,“ beforeunload”事件仅在firefox中触发

[英]'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.

相关问题 为什么当我单击页面时,浏览器的确认框(由beforeunload事件处理程序触发)才出现? - Why the browsers confirm box (triggered by beforeunload event handler) only appears when I click onto the page? 在Firefox中刷新页面上的beforeunload事件 - beforeunload event on page refresh in firefox 单击拖动项目时触发的事件(Firefox) - click event that fires when dragging an item (Firefox) 即使我单击停留在页面上,事件也会触发window.beforeunload - Even i click Stay on Page, event fire window.beforeunload 在firebug中查看页面时,我可以看到单击按钮时会触发哪个事件? - when viewing a page in firebug, can I see which event fires when I click a button? Firefox - 使用“beforeunload”事件时出现“此页面要求您确认是否要离开”消息 - Firefox - “This page is asking you to confirm that you want to leave” message when using “beforeunload” event 离开页面时不触发jQuery beforeunload事件 - JQuery beforeunload event not firing when leaving the page “点击”事件仅在首次点击时触发,而在第二次点击时不触发 - 'click' event only fires on first click and not second 绑定到点击事件 - 事件只触发一次 - binding to click event - event only fires once 如何在退出浏览器会话时触发beforeunload事件 - How can I make the beforeunload event fire only when a browser session is exited
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM