Close Browser From Code Behind

  • Thread starter Thread starter infrazee
  • Start date Start date
I

infrazee

Guest
I am looking for a way of closing a web browser from Code Behind in Asp.Net without getting a confirm dialog box.

I have a solution that works with Internet Explorer but it does not work with Microsoft Edge.

The solution I am using at present is to open a new, blank Web Page that contains the following statement in the Page_Load event:

ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.open('CloseApplication.html', '_self', null);", true);


The file CloseApplication.html contains:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Close Page</title>
<script language="javascript" type="text/javascript">
var redirectTimerId = 0;
function closeWindow() {
window.opener = top;
redirectTimerId = window.setTimeout('redirect()', 4000);
window.close();
}

function stopRedirect() {
window.clearTimeout(redirectTimerId);
}

function redirect() {
window.location = 'default.aspx';
}
</script>
</head>
<body onload="closeWindow()" onunload="stopRedirect()" style="">
<center><h1>Please Wait...</h1></center>
</body>
</html>


The above works with IE but not with Edge.

Any help would be greatly appreciated.

Continue reading...
 

Similar threads

Back
Top