0

I have written a script manager to open a page in new tab. The scriptManager is called on a button click, I want when the button click is called the popup window should get close. Please see my scriptmanager.

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", String.Format("window.open('{0}','_tab ')", ResolveUrl("dummy.aspx")), true); 

Please help to close the popup window

Nad
  • 4,605
  • 11
  • 71
  • 160
  • While this is technically possible to do if the new window is in the same domain as the parent window, there are a number of security and usability reasons why this is a bad idea. If you need to open a window that the parent page has control of, consider using an ajax popup window instead. http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx – Dave Oct 21 '14 at 14:30
  • can u help me with the code. The page is not opening – Nad Oct 21 '14 at 14:42
  • Sorry, old link. Try this one: https://ajaxcontroltoolkit.codeplex.com/wikipage?title=ModalPopup%20Control&referringTitle=Tutorials – Dave Oct 21 '14 at 14:43

2 Answers2

0

You can save instance of window.open and use that instance to close. Like declare global variable in aspx , say var win; in script tag, modify ScriptManager to use following.

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", String.Format("win = window.open('{0}','_tab ')", ResolveUrl("dummy.aspx")), true);

And if you want to close the pop up , from the page who opened popup, then use following

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup","win.close();", true);

And if you want to close with in popup page, then use following.

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup","window.close();", true);

Having said all of these, there is BIG disclaimer. In short, close does not work most of times, because of browser security. Following are the details.

Actually due to security reason and user experience aspects you can now can't cause the browser to be closed[Completely], only popup windows can be closed or the one parent to a script.

Just go through this - window.close and self.close do not close the window in Chrome More link - http://www.w3.org/TR/html51/browsers.html#dom-window-close

Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
0

Got it done, In another way. As the senior management told to to it another way.

Nad
  • 4,605
  • 11
  • 71
  • 160