如何避免“你确定要离开该页面?走”时提交的修改? 在IE的GridView的分页点击(How t

2019-10-20 06:02发布

我的网页包含有许多输入fields.I要移动到下一个标签之前给予警告用户网格视图。 我的剧本是工作的罚款在Mozilla Firefox和Chrome,但在IE浏览器的警报也即将并网观点分页click.I不想上显示在Mozilla分页click.but和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>

如何避免此消息在GridView的分页点击仅IE的? 任何人可以帮助我吗?

谢谢

Answer 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); 


文章来源: 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