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>

 

Published 12 January 2007 05:40 AM by haissam

Comments

# Sachin Makwana said on 30 March, 2007 07:27 AM

Really helpful

Thanks

# Rashmi said on 13 April, 2007 05:51 AM

Perfect!

# Ravi Kumar said on 18 April, 2007 05:26 AM

Its not working for IE7

# haissam said on 20 April, 2007 05:22 AM

Check the below post blog.

http://dotnetslackers.com/community/blogs/haissam/archive/2007/04/20/Javascript_3A00_-Close-window-without-the-prompt-message-in-IE7.aspx

Thank you for your comments.

Best Regards,

HC

# Johnny C said on 12 September, 2007 11:22 AM

U tha Man!!!

# salih said on 04 January, 2008 11:18 AM

no working

# Unknown Friend said on 06 March, 2008 01:32 AM

Hii It works in any explorer without warning close window  

     function windowclose() {

      this.focus();

      parent.opener = this;

      parent.close();

     }

# Om said on 21 September, 2009 07:37 PM

It works..thanks

# 3mie said on 17 November, 2009 02:01 PM

it does not work. anyways thank you

This site

Search

Go

This Blog

Syndication

Sponsors

  • MaximumASP
  • Social Bookmarking
    Online Shopping
    asp.net hosting
    UK online local dating