...

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



VijayKumar
07-10-2006, 10:53 AM
hello,

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 MENUBAR_HEIGHT = 10;
var TOOLBAR_HEIGHT = 50;
var STARTUPBAR_HEIGHT = 10;
var heightOfBars = MENUBAR_HEIGHT + TOOLBAR_HEIGHT + STARTUPBAR_HEIGHT;
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
window.opener.opener=''
opener.window.close();


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

mkeehan
07-10-2006, 12: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
}

A1ien51
07-10-2006, 02: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.

Eric

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

And

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..

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

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

window.opener=null;window.name="XYZ";window.open("","XYZ").close()

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum