为了账号安全,请及时绑定邮箱和手机立即绑定

对话框运行1秒后消失?

对话框运行1秒后消失?

慕妹3146593 2019-09-06 11:06:03
对话框运行1秒后消失?用户离开页面时,我正在运行一个对话框。唯一的事情是它运行1秒并消失?我知道它与此有关bind('beforeunload'),但对话框的死亡时间比你能读到的要快。我如何阻止这种情况发生?$(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 回答

?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

在我的情况下,我在转到我的webapp的另一部分之前使用它来显示“预加载器”,因此这与打开的新页面中出现的“预加载器”匹配,以便在页面之间进行美学更改。

它对我有用(我尝试了一切),是这样的:

function myLoader() {
    // Show my Loader Script;}$( window ).on( 'beforeunload' , function() {
    myLoader();} );



查看完整回答
反对 回复 2019-09-10
  • 3 回答
  • 0 关注
  • 387 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信