2016-04-15 74 views
0

我使用window.open()「beforeunload」事件僅在Firefox火災時,我點擊頁面

打開一個新的窗口,然後我想,當用戶關閉運行一些腳本(一個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中運行良好。

但是在火狐I 手動必須點擊關於HTML或做一些互動。如果我嘗試關閉窗口而不做任何事情,'beforeunload'事件似乎根本不會觸發。

+0

任何解決方案? –

+0

@IonicăBizău你有沒有找到解決辦法? im撓我的頭髮 – slier

+0

@slier不,這只是Firefox的工作方式(除非你改變'about:config' - 如下所述 - 可能你不想這麼做)。恐怕沒有辦法強制這一點。 –

回答

0

Firefox有一些配置,您可以在導航工具欄中找到「about:config」。在那裏你會發現一些標誌,包括dom.require_user_interaction_for_beforeunload這使得'beforeunload'事件只有當你點擊頁面時纔會觸發。但是你不能通過代碼修改這個配置;您必須在Firefox中手動執行此操作。 PS:對不起,我的英文不好。