View Full Version : Opening a customized window with same url and closing the parent windo

07-10-2006, 11:53 AM

here is a requirement.

Opening a link in the browser has to open a new window with same url content (url cannot be hardcoded)

and the opened window must close the parent window and should not have any of the status bar,url bar or menu bar.

I have written this code in a html page in the body onload event

var WIN_WIDTH = 700;
var WIN_HEIGHT = 500;
var xPos = (screen.width/2) - (WIN_WIDTH/2);
var yPos = (screen.height/2) - (WIN_HEIGHT/2) - heightOfBars;

var prop='menubar=no,scrollbars=no,status=no,locationbar=no,'+'toolbar=no,resizable=yes,width='+WIN_WIDT H+',height='+WIN_HEIGHT + ',left='+xPos+',top='+ yPos;

window.open (location.href,'EKMIS',prop);

//closes parent window without any confirmation

But the problem is opened window goes into unending loop..

07-10-2006, 01:08 PM
You just need to test if the window was opened by another window. If it was, then don't run rest of the onload code.

So, inside your onload function:

if (window.opened) {
return true;
} else
//your code here

07-10-2006, 03:32 PM
ALL BROWSERS that are patched will not allow you to close the parent window if you did not create it with JavaScript. SO you are out of luck here. Leave our windows alone. If I come to a site and it tries to change my window, I normally leave.

If you are doing this presentation for more room. Try to redesign. If you are doing it for security reasons. It is a waste of time since the people you are hiding it from know how to get around it. If you are hiding it because it is effecting code on the server, you better learn how to fix it in the back end.


07-11-2006, 06:29 AM
The code
if (window.closed){return true;}else{//code} is not working


Requirement i mentioned is not meant for a website but for a java web application.so trying to get around to view the content is handled by blocking the viewers and redirecting them to login screens.not concerned abt the security reasons,nor presentation.

So if the parent window is closed crucial session information is lost once i open a new window, which is my requirement,
New window has nothing but 2 input fields,which submit the data to server and ends the application.

Cannot customize window from the forwarded page (coz i cant send any information to the forwarded page as it is handled by Application server-basic authentication procedure)

Since my window is created from javascript, i am able to close parent window but not able to stop the un-ending loop of creating new window.

Got any suggestions for that..

07-12-2006, 05:36 AM
Maybe a cookie to track if the window replace has already been done.

08-22-2006, 09:25 AM
well, it IS possible to close the current window... try


this works for me in both IE and Gecko (Firefox,...)

A1ien51 is still right to point out that only windows created by a script can be closed by the same script. The code above does just that. It reopens the current window thereby obtaining a new window handle which it can call close() upon.

To fix the endless loop I would suggest you give the new window a certain name which you can query to see if you're already in the new window.