How can I close all IE browser windows that I opened in JavaScript?

How to close IE browser window in asp.net,

I open a lot of windows ... from javascript by window.open () ... I need to close all the windows by clicking the button on the main page (parent window).

several times we open inside C # it self

btnShow.Attributes.Add("onclick", @"var windowVar=window.open('" + sAppPath + @"', 'parent');windowVar.focus(); return false;");

while I can add an array to javascript.

How can i do this?

+3
source share
3 answers

Concept

Whenever you open a window from the main page, keep a link to the open window (pushing it onto an array works well). When the home page button is clicked, close each link window.

Script Client

JavaScript . HTML ASPX.

var arrWindowRefs = [];
//... assume many references are added to this array - as each window is open...

//Close them all by calling this function.
function CloseSpawnedWindows() {
   for (var idx in arrWindowRefs)
      arrWindowRefs[idx].close();
}

:

// Spawn a child window and keep its reference.
var handle = window.open('about:blank');
arrWindowRefs.push(handle);

JavaScript window.open(..) .

, JavaScript .

, HTML-

<input type="button" 
    name="btn1" id="btn1" value="Click Me To Close All Windows"
    onclick="CloseSpawnedWindows()">

ASP.NET, JavaScript

<asp:Button ID="Button1" runat="server" Text="Click Me To Close All Windows" 
        OnClientClick="CloseSpawnedWindows()" />

ASP.NET script ( PostBack AJAX)

aspx , ( ). , AJAX , .

( Framework 3.5)

ASP.NET AJAX - ScriptManager UpdatePanel ( ).

<%@Page... %>

<asp:ScriptManager EnablePartialRendering="True" /> Enable AJAX.

<script>
// PUT JAVASCRIPT OUT HERE SOMEWHERE.
// Notice the client script here is outside the UpdatePanel controls,
//  to prevent script from being destroyed by AJAX panel refresh.
</script>

<asp:UpdatePanel ID="area1" runat="server" ... > ... </asp:UpdatePanel>
<asp:UpdatePanel ID="area2" runat="server" ... > ... </asp:UpdatePanel>
etc...

ASP.NET AJAX , , .

, AJAX , script, , .

+10

, , close(), .

<script>
var myWindow = window.open('http://www.google.com/');
var myWindow2 = window.open('http://www.bing.com/');

function closeAll()
{
    myWindow.close();
    myWindow2.close();
}
</script>

<input type="button" onclick="closeAll();" value="Close all" />
+2

, . JS , .

referenceToWindowObject.close()

, JS .

ASP.NET, , () , ( window.open) , .

, , - , () .

0

Source: https://habr.com/ru/post/1725806/


All Articles