2013-03-19 27 views
2

這裏是我的代碼:Internet Explorer的火災時,收藏夾彈出

$(window).on('beforeunload', function() { 
    if ($('.jqmCustomize').css('display') == 'block') 
    return 'You have not save your customization yet.'; 
}); 

這適用於Chrome和Firefox罰款,但在Internet Explorer,它觸發對( 'beforeunload')當我的燈箱在同一頁面打開時發生的事件。有什麼辦法可以防止這種情況發生?我試圖:

var close=true; 
window.onbeforeunload = closeConfirmation; 
function closeConfirmation(){ 
    if(close) 
    return 'You have not save your customization yet.'; 
} 

但我仍然得到相同的結果。

+0

你能解釋這個問題有點更詳細的? 什麼是你的'.jqmCustomize',什麼是燈箱,你想做什麼? – inser 2013-03-19 20:47:13

+0

.jqmCustomize是我使用jqmodal插件的燈箱。我正在檢查jqmCustomize是否可見,比關閉頁面之前,詢問用戶是否要關閉,因爲他們將有一些數據保存在jqmCustomize上。這對鉻和FF工作得很好,但在即,當jqmCustomize燈箱打開,即認爲用戶點擊關閉頁面按鈕,並觸發onb​​eforeunload。 – 2013-03-19 20:53:46

回答

0

其實我沒有看到任何問題。 可能是我使用的是舊版本jqmodal和jQuery的,但它按預期工作:

http://jsfiddle.net/xqhLx/5/

$(function($){ 
    $('#jqModal').jqm(); 

    $('a').live('click',function(){ 
     $('#jqModal').jqmShow();  
     return false; 
    }); 
}); 

$(window).on('beforeunload', function() { 
    if ($('.jqmWindow').css('display') == 'block') 
    return 'You have not save your customization yet.'; 
}); 

HTML:

<a href="/" >Test</a> 

<div id="jqModal" class="jqmWindow" style="display: none;">This is the test</div> 
+0

已更新至jqmodal的最新版本,但仍存在相同的問題。 – 2013-03-19 21:28:49

+0

你檢查我的例子嗎? 是你期望的嗎? – inser 2013-03-19 21:35:40

+0

是的,你的例子就是我期望在我的情況下發生的事情。但是,也就是說,當顯示jqmodal時,在觸發事件之前的無效事件。嗯,它是當點擊。 – 2013-03-19 21:37:06