Close Window Without Warning Message - Javascript

If you have ever tried to close a window and receive this warning "The page is trying to close the window", this warning message shows up everytime we use window.close(). to solve this issue we have to look at how window.close() works

window.close() looks to the opener window, if it's equal to empty string it displays this kind of message, so to bypass this all you need to is to set the opener to a string and then use the close() function

<script language="javascript">

function CloseWindow()

{

window.opener = 'as'; // Or window.opener = self;

window.close()

}

</script>

 

Comments

# re: Close Window Without Warning Message - Javascript

Friday, March 30, 2007 7:27 AM by Sachin Makwana

Really helpful

Thanks

# re: Close Window Without Warning Message - Javascript

Friday, April 13, 2007 5:51 AM by Rashmi

Perfect!

# re: Close Window Without Warning Message - Javascript

Wednesday, April 18, 2007 5:26 AM by Ravi Kumar

Its not working for IE7

# re: Close Window Without Warning Message - Javascript

Friday, April 20, 2007 5:22 AM by haissam

# re: Close Window Without Warning Message - Javascript

Wednesday, September 12, 2007 11:22 AM by Johnny C

U tha Man!!!

# re: Close Window Without Warning Message - Javascript

Friday, January 04, 2008 11:18 AM by salih

no working

# re: Close Window Without Warning Message - Javascript

Thursday, March 06, 2008 1:32 AM by Unknown Friend

Hii It works in any explorer without warning close window  

     function windowclose() {

      this.focus();

      parent.opener = this;

      parent.close();

     }

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.