Skip to main content

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.

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
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
Anonymous 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
Anonymous 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
Veena said…
Great

Popular posts from this blog

Script table as - ALTER TO is greyed out - SQL SERVER

One of my office colleague recently asked me why we are not able to generate ALTER Table script from SSMS. If we right click on the table and choose "Script Table As"  ALTER To option would be disabled or Greyed out. Is it a bug? No it isn't a bug. ALTER To is there to be used for generating modified script of Stored Procedure, Functions, Views, Triggers etc., and NOT for Tables. For generating ALTER Table script there is an work around. Right click on the table, choose "Modify" and enter into the design mode. Make what ever changes you want to make and WITHOUT saving it right click anywhere on the top half of the window (above Column properties) and choose "Generate Change Script". Please be advised that SQL Server would drop actually create a new table with modifications, move the data from the old table into it and then drop the old table. Sounds simple but assume you have a very large table for which you want to do this! Then it woul...

AWS fatal error: An error occurred (400) when calling the HeadObject operation: Bad Request

While using AWS and trying to copy a file from a S3 bucket to my EC2 instance ended up with this error message. Command Used: aws s3 cp s3://mybucketname/myfilename.html /var/www/html/ Error: fatal error: An error occurred (400) when calling the HeadObject operation: Bad Request The error goes off if we add the region information to the command statement. I am using Asia Pacific (Mumbai) so used ap-south-1 as the region name. Modified Command: aws s3 cp s3://mybucketname/myfilename.html /var/www/html/ --region ap-south-1

[Non Tech] Want to know the recipe for Omelette :)

Fed up with Bread - Jam and Curd Rice, today i wanted to eat Omelette. Interesting part is I wanted to cook it myself :) So in the first picture you see all the items which are needed for preparing an Omelette. When I had a closer look at the eggs I see that almost all the eggs are broken. But believe me when I bought it couple of days back it was in perfect condition! I was wondering whether the eggs have become rotten or pretty old to consume! I tried taking an egg and break it but couldn't break it at all :) Since I have kept in the freezer all the eggs have frozen and looked like a iron ball :) After trying for few minutes of trying i removed the shell of the egg and then kept that iron ball :) into a bowl and placed it within Oven. I heated it for 1 minute and checked. It melted only to a limit. So i just set it for another 2 minutes and checked it later. It has melted but the part of the egg white has become a Omelette :( I didn't leave it there. I took the bowl out of ...