【问题标题】:How to avoid the “Are you sure you want to navigate away from this page?” when changes committed? on pagination click of gridview in IE如何避免“您确定要离开此页面吗?”何时提交更改?在 IE 中点击 gridview 的分页
【发布时间】:2014-07-29 19:42:54
【问题描述】:

我的网页包含带有许多输入字段的网格视图。我想在移动到下一个选项卡之前向用户发出警报。我的脚本在 Mozilla Firefox 和 chrome 中运行良好,但在 IE 中,网格视图分页点击也会发出警报。我不想在分页点击上显示。但在 Mozilla 和 chrome 中,这不会发生。如何避免这种情况。

我在这里给出我的脚本

 <script>

    var warnMessage = "You have unsaved changes on this page!";

    $(document).ready(function () {
        $('input:not(:button,:submit),textarea,select').change(function () {
            window.onbeforeunload = function () {
                if (warnMessage != null) return warnMessage;
            }
        });
        $('input:submit').click(function (e) {
            warnMessage = null;
        });
    });



</script>

如何避免仅在 IE 中单击 gridview 分页时出现此消息? 谁能帮帮我?

谢谢

【问题讨论】:

    标签: javascript jquery asp.net gridview pagination


    【解决方案1】:

    只需在分页点击时将值设置为 null

       window.onbeforeunload = null;
    

    更新 1

    试试这个而不是你的代码:

      var myEvent = window.attachEvent || window.addEventListener;
        var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
        myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox
            var confirmationMessage = 'Are you sure to leave the page?';  // a space
            (e || window.event).returnValue = confirmationMessage;
            return confirmationMessage;
        });
    

    更新 2

    在你使用 window.onbeforeunload = null; 之后在您的分页控件中重新绑定更新面板中的警报尝试此解决方案,它可能会帮助您解决该问题:

       $(document).ready(function () {
         bindPageAlert();
       });
    
        function bindPageAlert()
        {
            var myEvent = window.attachEvent || window.addEventListener;
            var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';
            myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox
                var confirmationMessage = 'Are you sure to leave the page?';  // a space
                (e || window.event).returnValue = confirmationMessage;
                return confirmationMessage;
            });
        }
    
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPageAlert);
    

    【讨论】:

    • 当我设置“window.onbeforeunload = null;”分页后单击,如果我在文本框中进行任何更改并且没有保存它 m 导航到其他选项卡,那么它不会显示任何消息。
    • 只需确保在分页点击事件之后,再次调用您的 javascript 以将脚本重新绑定到您的页面。
    • 是的,我想要那个..但是你能告诉我怎么做
    • 那么您也需要提供分页控件
    • 当然.... $('.paginationstyle a').click(function (e) { window.onbeforeunload = null; });如果我在分页中执行此操作,请单击它没有显示任何消息..但是如何再次重新绑定它?
    猜你喜欢
    • 2010-11-10
    • 2012-06-26
    • 1970-01-01
    • 2016-12-31
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    相关资源
    最近更新 更多