简体   繁体   English

如何使用jQuery处理我的弹出窗口上的关闭按钮单击事件

[英]How to handle the Close Button click event on my popup window using jquery

I have this code in my Master page. 我的母版页中有此代码。

PopUpWindow = function (titles, message) {
      document.getElementById('window').innerHTML = message;
      $("#window").dialog({
          resizable: true,
          height: 140,
          title: titles,
          width: 500,
          message: "something here",
          modal: true,
          buttons: {
              "Close": function () {
                  $(this).dialog("close");
              }
          }
      });
  };


<div id="window" style="display: none;">

        </div>   

I can able to display the popup mesage perfectly.. My questions is.. 我可以完美显示弹出消息。.我的问题是..

I have this code in my controller. 我的控制器中有此代码。

 return new JavaScriptResult() { Script = "alert('saved Successfully Added. Thank You.'); window.location='/ObnCategory/Index';" };

I changed the code to 我将代码更改为

 return new JavaScriptResult() { Script = "PopUpWindow("saved","something here"); window.location='/ObnCategory/Index';" };

Here I am getting the popup perfectly but the problem is the popup closing automatically without clicing close button. 在这里,我可以完美地弹出弹出窗口,但是问题是弹出窗口会自动关闭而无需关闭按钮。 due to window.location? 由于window.location吗?

can any body tell me how to load the page after close button click.. 谁能告诉我在关闭按钮单击后如何加载页面。

PopupWindow is generic I can not keep window.location on popupwindow script? PopupWindow是通用的,我不能在popupwindow脚本上保留window.location吗?

thanks 谢谢

Put the window.location in the close handler... window.location放在关闭处理程序中...

PopUpWindow = function (titles, message, redirectURI) {
  document.getElementById('window').innerHTML = message;
  $("#window").dialog({
      resizable: true,
      height: 140,
      title: titles,
      width: 500,
      message: "something here",
      modal: true,
      buttons: {
          "Close": function () {
              $(this).dialog("close");
              if(redirectURI) { //Only redirect if param is specified!
                  window.location=redirectURI;
              }
          }
      }
  });
};

Then 然后

return new JavaScriptResult() { Script = "PopUpWindow("saved","something here","/ObnCategory/Index");" };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM