How can i close all the IE browser window in asp.net,
I am opening many windows..from javascript by window.open()…
I need to close all the windows by clicking the button in main page(parent window).
some times we have open in in c# it self
btnShow.Attributes.Add("onclick", @"var windowVar=window.open('" + sAppPath + @"', 'parent');windowVar.focus(); return false;");
at the time how can i put in array in javascript.
How can i do it?
Concept
Whenever you open a window from the main page, keep a reference to the opened window (pushing it onto an array works well). When the main page button is clicked, close each referenced window.
Client Script
This JavaScript is for the main page. This works for an HTML or ASPX page.
Opening a window and pushing it onto the above array looks something like this:
Microsoft’s JavaScript window.open(..) method and its arguments are outlined here.
Different browsers might have variations or proprietary ways to keep references to opened windows or to enumerate through them, but this pure JavaScript way is very compatible with browsers.
Button
Finally the HTML Input button to initiate the above code would be
If it’s an ASP.NET Button Control then call JavaScript this way
Troubleshooting ASP.NET client script (PostBack and AJAX fix)
If your aspx page posts back to the server, the client code will be destroyed and lose it’s array with child window references (and those windows will remain open). If this is a concern, you might want to use AJAX for partial page refreshes, to prevent the entire page and its scripts from being destroyed.
(Shown using Framework 3.5 samples)
For ASP.NET AJAX you’ll be using something like a ScriptManager instance to enable partial page refresh inside UpdatePanel controls (lots of samples).
A lot more detail about ASP.NET AJAX can be provided but this is just a start in case you need it.
Remember, in the case of AJAX, don’t refresh the part of the page containing the above Client Script because you want it to persist the array through server callbacks.