Wednesday, February 04, 2004

Closing the parent window ...

Many times I have been asked how to close a parent window without getting that ugly warning dialogbox. You know what the solution is pretty straight forward :)

Script of the Parent window:

<html>
 <head>
  <Script language=""javaScript"">
   window.opener=self;
   window.close();
   window.open('test.htm','Test','fullscreen');
  </script>
 </head>
 <body>
 </body>
</html>

Here 'Test' is a name of the window. You can give any name of your choice there. 'test.htm' is the name of the file which would be opened in fullscreen. This way we could avoid that ugly warning dialogbox.

19 comments:

satish said...

hi
I tried this code.But not working .I dont know what is the problem.Can you help in this regard.
My code is as follows:


function samewindow()
{
window.opener=this;
window.close();
window.open("http://www.google.com");

}

this is called by a onClick event on a button.


Thanks in advance.
Satish

Gopi said...

Gr8

Anonymous said...

To close the parent window and leave child window open....

function shutwindow(){
window.open('','_parent','');
window.close();
}

Anonymous said...

THANKS!!!

Paul

Anonymous said...

Excellent thank you!

alok said...

hi i tried it but it's not working with mozilla 2.0 or higher and in ie7.0 its giving a prompt to close window... any other solution or link will be appreciated ...

Alok

Siria said...

The following code for closing the parent window without a message box works with IE7 but not with Firefox:

function getpage()
{
window.open("","_self","")
window.close();
window.open("newpage.aspx","newpage","toolbars=no,location=no,resizable=no")
}

Anonymous said...

Hello,

i am not being able to the parent window with this code using C# aspx from within a windows form...any hlep

Anonymous said...

Thanks

Kiran said...

Thank You !!!!!

nessy00 said...

I`ve tried it and it works, but a question appear asking if i really want to close the window. Can I do sth not to appear this message??

Thanks

Anonymous said...

In order to get IE to close a window without the prompt the window must either have no history or be opened from javascript. I load my page back into the same window with "body onLoad="myLoader()"

Now you've created a browser window created from javascript, it is just the same page reloaded, but this time from you page script.

Then myLoader will have:

widow.open('this same page','_self'); //open your page again, but this time from javascript, load in same window
window.opener=''; //not sure if needed, doesn't seem to hurt
window.close(); //this closes the original window
window.open('your target window'),'other','parameters as need')

When this page is called it reloads itself, opens the new target page in a new window, then closes itself. Now to get it to close in Netscape, that is a whole different story.

Yoyox Indonesia said...

try this onclick="window.open('url','_parent')", in onclik button :D

fuzzy757 said...

was seaching for this from long time thanks :D

iterebin said...

And how to maximaze the child window affter oppening?

senthl said...

i want to know thiswindow opening command in java... pls give...

ram said...

hi
great..........

ram said...

hi
great..........

Anonymous said...

thanks
Its really awesome