對(duì)話框運(yùn)行1秒后消失?用戶離開(kāi)頁(yè)面時(shí),我正在運(yùn)行一個(gè)對(duì)話框。唯一的事情是它運(yùn)行1秒并消失?我知道它與此有關(guān)bind('beforeunload'),但對(duì)話框的死亡時(shí)間比你能讀到的要快。我如何阻止這種情況發(fā)生?$(document).ready(function() {
// Append dialog pop-up modem to body of page
$('body').append("<div id='confirmDialog' title='Confirm'><p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>Are you sure you want to leave " + brandName + "? <br /> Your order will not be saved.</p></div>");
// Create Dialog box
$('#confirmDialog').dialog({
autoOpen: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
'I am sure': function() {
var href = $(this).dialog('option', 'href', this.href);
window.location.href = href;
},
'Complete my order': function() {
$(this).dialog('close');
}
}
});
// Bind event to Before user leaves page with function parameter e
$(window).bind('beforeunload', function(e) {
// Mozilla takes the
var e = $('#confirmDialog').dialog('open').dialog('option', 'href', this.href);
// For IE and Firefox prior to version 4
if (e){
$('#confirmDialog').dialog('open').dialog('option', 'href', this.href);
}
// For Safari
e.$('#confirmDialog').dialog('open').dialog('option', 'href', this.href);
});
// unbind function if user clicks a link
$('a').click(function(event) {
$(window).unbind();
//event.preventDefault();
//$('#confirmDialog').dialog('option', 'href', this.href).dialog('open');
});
// unbind function if user submits a form
$('form').submit(function() {
$(window).unbind();
});});
3 回答

人到中年有點(diǎn)甜
TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
在我的情況下,我在轉(zhuǎn)到我的webapp的另一部分之前使用它來(lái)顯示“預(yù)加載器”,因此這與打開(kāi)的新頁(yè)面中出現(xiàn)的“預(yù)加載器”匹配,以便在頁(yè)面之間進(jìn)行美學(xué)更改。
它對(duì)我有用(我嘗試了一切),是這樣的:
function myLoader() { // Show my Loader Script;}$( window ).on( 'beforeunload' , function() { myLoader();} );
- 3 回答
- 0 關(guān)注
- 435 瀏覽
添加回答
舉報(bào)
0/150
提交
取消