Welcome to AspAdvice Sign in | Join | Help

bypass "The Web page you are viewing is trying to close the window" - (simple)

if you are closing a page using javascript in IE

window.close()

it will prompt an Microsoft Internet Explorer message

"The Web page you are viewing is trying to close the window",

to avoid / bypass this alert / message,

you need to assign the page you going to close with

window.opener = "to some value";

this is because if you want to close a page directly the page should have a opener

thus by assigning the page with a opener value, the page can be close by calling window.close() subsequently

Sponsor
Published Wednesday, September 20, 2006 5:16 PM by mo meng

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Thursday, October 26, 2006 2:44 PM by lilly

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

great
Thursday, November 09, 2006 2:51 AM by Ishwar

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

I tried this method but it does not seem to work. I have a parent window which creates a child window and the child window creates another child, on the unload() of which I am trying to close the parent windows. Require Help on this ASAP. I am able to close the intermediate parent/child but not the parent of the intermediate parent/child.

Monday, November 13, 2006 10:36 PM by mo meng

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

hi,

sorry for late reply.

you can try this

eg.

window A opens window B.

window B opens window C.

if at the unload function in page B u want to close window A.

parent.opener.opener=''

parent.opener.close()

if a the unload function in page C u want to close window B,

window.opener.close()

(you do not need to assign the opener value since its already have a opener (window B))

close window A from window C,

parent.opener.opener.opener=''

parent.opener.opener.close()

Monday, November 13, 2006 11:03 PM by mo meng

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

hi, sorry for late reply. you can try this eg. window A opens window B. window B opens window C. if at the unload function in page B u want to close window A. parent.opener.opener='' parent.opener.close() if a the unload function in page C u want to close window B, window.opener.close() (you do not need to assign the opener value since its already have a opener (window B)) close window A from window C, parent.opener.opener.opener='' parent.opener.opener.close()
Wednesday, November 15, 2006 11:18 AM by Mike

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Haha - works great. Thanks!
Thursday, January 11, 2007 1:16 AM by Xing

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

It is not working in IE7. Can anybody help me! ...head... function wClose() { window.opener = ''; window.close(); } ...head... ...body... Close ...body...
Thursday, February 22, 2007 9:06 AM by kody

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

check microsoft official site for IE7 version.

http://msdn2.microsoft.com/en-us/ie/aa740486.aspx

it is not allowed anymore in IE7.

Monday, February 26, 2007 3:09 AM by mo meng

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

window.opener and window.close--Internet Explorer 7 no longer allows the window.opener trick to bypass the window.close prompt. Browser windows cannot close themselves unless the windows were created in script. This security enhancement no longer allows browsing to a random site when the main browser window closes unexpectedly.

Thursday, March 22, 2007 5:50 PM by Jennifer

# Fix Found

hack found for IE7 and FF: http://www.interwebby.com/blog/2006/02/04/3/
Thursday, April 05, 2007 12:03 AM by mo meng

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

good one

Tuesday, April 24, 2007 10:44 AM by Bonnie

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

The IE7 hack works in IE7 but won't close the window on IE 6

Tuesday, May 08, 2007 4:23 AM by mo meng

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

how bout .. in the javascript u check on the browser version n than include the different javascript

if (window.XMLHttpRequest){

//script for IE 7

}else{

//script for lower than IE 7

}

this should work

Saturday, September 08, 2007 10:42 AM by Matei's blog

# Close window from JavaScript

Close window from JavaScript

Thursday, November 01, 2007 7:07 AM by priyadharsinni

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Hi ,

I am trying to close the child window from the parent unload event.. when the user tries to close the parent window automatically close the dependent ( child ) window too...

And in the Child window's onbeforeunload i am calling some of the script functions of the parent window...

i am not able to bypass that default window asked by IE6. where i have to set the window.opener=''..

Can anyone pls help me...

Parent page Script:

function CloseDependentWindow()

{  

   if (newnoteflag==1 && !windowflag==1)

   {            

      return "Are you sure want to navigate away from this page?";

   }

}

function CloseNewNoteChild()

{

   if (newnoteflag==1 && !windowflag==1)

   {  

           closeflag=1;

           if (windowHandle1 && windowHandle1.open && !windowHandle1.closed)

           {                                      

               windowHandle1.close();

               self.close();                                  

           }        

    }

}

window.onunload=CloseNewNoteChild;

window.onbeforeunload=CloseDependentWindow;

Popup Page Script:

function confirmExit()

    {                        

       cflag=window.opener.GetCloseFlag();

       if (saved==false && cflag==0)

       {            

           window.opener.ResetnewnoteFlag();

           return "Your new note has not been saved!!!";        

       }

    }          

    function SuppressDefaultWindow()

    {      

       if (cflag==1)

       {

           window.opener='';

       }

    }

    window.onbeforeunload    = confirmExit;

    window.onunload=SuppressDefaultWindow;        

Can anyone pls help me ?

Monday, November 05, 2007 3:38 AM by mo meng

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

well priyadharsinni .. i din very get what u want but if get u correct .. u want to close the child page from the parent window .. maybe u can try to set

function CloseNewNoteChild()

{

  if (newnoteflag==1 && !windowflag==1)

  {  

          closeflag=1;

          if (windowHandle1 && windowHandle1.open && !windowHandle1.closed)

          {                                      

             windowHandle1.opener='';

              windowHandle1.close();

              self.close();                        

          }        

   }

}

Friday, November 16, 2007 6:52 PM by Sarita

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

This one helped! Thanks!!
Tuesday, January 08, 2008 7:01 AM by Chris

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

I just used the following and it works on both IE6 and 7; BLOCKED SCRIPTwindow.opener='Self'; window.open('','_parent',''); window.close();
Thursday, January 10, 2008 7:22 AM by Rob

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Where abouts does this line of code need to be positioned? I am a bit confused.
Monday, May 12, 2008 10:46 AM by Geoge

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Thank you thank you for the hack.  You have made my application work now, and mucho mucho kudos and karma going out to you.  I have been fighting Microsofts attempts to clobber javascript, since they do not own it since 1996, and  feel like Quixote, but the windmills will not win.  :-D

Saturday, July 26, 2008 6:23 PM by Richard

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Brilliant workaround. Thank you :-)
Tuesday, August 05, 2008 3:09 AM by vishal

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Hello Everybody,

I found cool solution of this problem at <a href='http://technoexperts.blogspot.com/2008/08/close-window-without-javascript-alert.html'>Close windows without javascript alert</a> website for Details.

Friday, August 08, 2008 8:03 AM by jams

# re: bypass &quot;The Web page you are viewing is trying to close the window&quot; - (simple)

Thanks vishal.. Really this is cool colution http://technoexperts.blogspot.com/2008/08/close-window-without-javascript-alert.html. Thanks once again.
Sunday, August 31, 2008 2:24 AM by vishal

# re: bypass "The Web page you are viewing is trying to close the window" - (simple)

Monday, September 08, 2008 8:07 AM by gkn

# re: bypass &quot;The Web page you are viewing is trying to close the window&quot; - (simple)

lol, each time someone get a hack, MS blocks it... (can't wait for IE8....)
Tuesday, February 24, 2009 2:28 AM by Sixty_four_bit

# re: bypass &amp;amp;amp;quot;The Web page you are viewing is trying to close the window&amp;amp;amp;quot; - (simple)

Thanks Cris, It worked. SCRIPTwindow.opener='Self'; window.open('','_parent',''); window.close();
Friday, March 13, 2009 6:10 AM by anon

# re: bypass &amp;amp;quot;The Web page you are viewing is trying to close the window&amp;amp;quot; - (simple)

The solution by Chris works a treat. Brilliant.
Friday, November 27, 2009 11:06 AM by MMS

# re: bypass &quot;The Web page you are viewing is trying to close the window&quot; - (simple)

Brilliant Solution, thanks very much Chris.

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below