在带有colorbox弹出窗体的表单上添加“你确定要保留页面而不保存”

时间:2013-02-11 21:35:21

标签: javascript jquery popup colorbox

我在弹出式彩色框上有一个表单,如果用户编辑其中一个文本框然后点击取消,我想要一个弹出窗口,显示“你确定要离开而不保存吗?”。目前我有弹出窗口显示但在弹出颜色框已经关闭后显示

用户页面

 $('a.openDialog').colorbox({
                iframe: true,
                transition: "elastic",
                width: "75%", height: "90%"
            });

实际表格页

 $(':input', 'form').bind("change", function () {
                setConfirmUnload(true);
             });


function setConfirmUnload(on) {

              window.onbeforeunload = (on) ? unloadMessage : null;
          }

          function unloadMessage() {
              return 'You have entered new data on this page.' +
        ' If you navigate away from this page without' +
        ' first saving your data, the changes will be' +
        ' lost.';
      }

2 个答案:

答案 0 :(得分:2)

如果没有帮助你可以在关闭按钮或div上添加一个监听器,你可以使用Colorbox回调onCleanup或onClose

答案 1 :(得分:0)

我找到了解决方案,你必须在这里调用colorbox的oncomplete函数是代码

$("#cboxClose").click(function (e) {

                        // stop any other script from firing
                        e.stopPropagation();

                        if (confirm('You have unsaved changes, are you sure that you want to cancel? All of your changes will be lost.')) {
                            $.colorbox.close();
                            // ensure that the binding is removed when closed
                            $("#cboxClose").unbind();
                        }

                    });

                } // close oncomplete