Click here to Skip to main content
15,923,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In asp.net2.0 in javascript on giving window.close("index.aspx"); i am getting a confirm box as "the webpage yor are viewing is trying to close?..." how to avoid this confirm box?

following is my code:

C#
<script type="text/javascript" >
function pageopen()
{
var Hid = document.getElementById('HiddenFieldCity');
var HidA = document.getElementById('HiddenFieldArea');
var HidC = document.getElementById('HiddenFieldComm');
var HidD = document.getElementById('txtDate');
if (document.getElementById('ddlone').value=="Select Here")
{
alert("Please Select City");
return false;
}
window.open('Home.aspx?hid=' + Hid.value + '& HidA=' + HidA.value + '& HidC=' + HidC.value + '& HidD=' + HidD.value + '',"Welcome","titlebar=0,fullscreen=0,addressbar=0,left=0,top=0,maximized=yes,width=1024,height=700,scrollbars=no,resizable=yes")
window.close("index.aspx");
}
Posted
Updated 11-Jun-13 21:07pm
v2

Try this snippet. I hope it will work(Example)

<a href="" onclick="CloseWindow();">Close Window</a>



XML
<script language=javascript>

function CloseWindow()

{

window.open('','_self','');

window.close();

}

</script>
 
Share this answer
 
v2
Problem

Refer - Bypass IE “The webpage you are viewing…” pop up[^].
Quote:
Your JavaScript code can only close a window without confirmation that was previously opened by window.open(). This is an intentional security precaution because a script running on a webpage does not own the window, and by closing it discards the browsing history in that window.

The workaround is to either have a "welcome page" or otherwise some sort of page that pops up the window you want to close with window.open in the first place, or to tell your users to modify their browser security settings to allow your application to close their windows.
So, the problem is that you are trying to close "index.aspx", which you have not opened by javaScript window.open. You can only close the window which is opened by winow.open.

Solution

In that case, you may try workarounds mentioned in the below links -

1. Close window without the prompt message in IE7[^].
2. The webpage you are viewing is trying to close this window warning in Internet Explorer[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900