Close a popup window that has been redirected
I'm having an issue getting a popup window to close on my page using JavaScript
I've been able to get other popup windows to close, but I think I'm losing something when I end up redirecting the popup window. For example, on the main window I select a project and the popup appears giving the information. Next I click on edit which does a response redirect to the edit page. Here I do my changes and hit submit. Upon submission I want it to close but I can't seem to get it to do that.
For previous popups I would use
ClientScript.RegisterStartupScript(this.GetType(), "CLOSE", "CloseAndRefresh();", true);
To call the javascript I have sitting in my .aspx file. Which is this:
function CloseAndRefresh() {
parent.location.reload(true);
parent.ClosePopup();
}
I generated the popup window with the following co开发者_JAVA百科de:
editButton.OnClientClick = (popupWindow.GetTargetPopupCode("MYURL"));
This however isn't working anymore. I think that due to my redirection of the original popup window it's throwing everything off. Any idea what I need to fix?
Edit:
I've finally got to the point that the javascript is actually getting called.
I've tried these functions and none have worked:
window.close();
self.close();
parent.ClosePopUp();
ww = window.open(window.location, "_self");
ww.close();
Thanks!
Okay, you might be doing things to closely together. Adding a timeout might help. This is code that I use to refresh the parent and close a popup. Adapt this, and see if it helps:
refreshParent = function(){
window.opener.reload();
setTimeout(function(){ self.focus(); self.close(); }, 2000);
}
Try using this:
EDIT: Removed true parameter from location.reload method, per W3 specification:
function CloseAndRefresh() {
parent.location.reload();
self.close();
return true;
}
See: http://www.w3schools.com/jsref/met_loc_reload.asp
EDIT: Instead of adding it as a startup script, try just adding it to the ClientOnClick of the submit button, like this:
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return CloseAndRefresh();" OnClick="..." />
精彩评论