Hi all,,

the problem is that i have a link in jsp on which i have to open a new jsp page and at that time i want the parent window to be closed ...without any alert to be displayed...
plzz help

Recommended Answers

All 8 Replies

the only way you could do that would be if your first window is opened by javascript (or maybe by named target).

otherwise, it would be an irritation risk if sites could close the browser.

if you want the parent window to close when a new page opens, why not just open the new page in the same window?? O_o

...perhaps that's not true.

in Opera:

<html>
<head></head>
<body>
<script type="text/javascript">
window.close();
var newWindow = window.open('/home/matt/test3.html');
</script>
</body>
</html>

works whether the window that processes that code was opened via a javascript process or not..

...interesting info.

by the way. you will probably get an alert or 2 if that kind of thing is done on a browser that's alert-ridden, like IE7.

FOLLOWUP:
Even on an oldish version of Firefox (1.0.2), the correct behaviour is adhered to; the correct behaviour being that only script-generated windows can close themselves or be closed. Proofing is as follows:

File #1 (test1.html)

<html>
<head></head>
<body>
<script type="text/javascript">
alert("Opening test2 in a new window");
var newWindow = window.open('/home/matt/test2.html');
</script>
</body>
</html>

File #2 (test2.html)

<html>
<head></head>
<body>
<script type="text/javascript">
alert("Closing test2's window");
window.close();
var newWindow = window.open('/home/matt/test3.html');
</script>
</body>
</html>

File #3 (test3.html)

(doesn't matter)

Opening the browser on test1.html causes test2.html to be opened in a new window, then that window is closed and test3.html is loaded in another new window.

Opening the browser on test2.html causes test3.html to be opened in another window: but the window holding test2.html doesn't close.

There was also a 'popup blocked' bar until I allowed popups from my local machine. That would be present in most browsers. Except the ultimate Opera of course..

the problem still persists....i can't open the new window in the same as i want to logout from the current page to a new logout page without any information to be shared ......and also can't use new window to popup with an alert ...........

well, if you're automatically opening windows you're always going to hit an alert on newer browsers, and you can only be sure you'll be able to close a window that you "own".

information doesn't have to be shared between the two pages. if you're worried about people pressing the 'back' button; that's a system beyond your control.

if you're using sessions (cookies/QSA) of some description, you can expire or invalidate the login; the users wont have authorititave access to your site after logging out; but they'll always be able to recall their cache.

The only way around that is 'scrambling' delivered pages and using JavaScript to 'unscramble' page content based on a cookie everytime a page loads. But even that won't stop browsers like Opera from recalling pages (it retains DOM/JS state between pages)

ya ...but i would like to discuss the problem once again,and hope that some1 can give me a help..
i have a jsp page main ,containg two frames in which 2 different jsp r loaded.....one of them has a logout link....wht i want is to click on the logout link closes the main jsp page that contains both of them and opening another jsp for the logout...in a totally new window.....might b the problem is now more clear and have a quick solution..

You wont get a quick solution for the reason's I've already outlined. You'll need to redesign the entry to your website so that the main window is lanched using JavaScript (in order to close the main window) and accept that popup blockers / security rules might interfere with what you want to do.

Regardless of whether your page is JSP/ASP/PHP/HTML and whether you have no frames or 75 frames, th questions you want the answers to are:

- Can I close the current browser window?
Only if you opened it from script on your site, or if you're targetting browsers that ignore the rules for window ownership. Even if you 'own' the window; you may hit security problems in certain browsers, especially on high security modes.

- Can I open a new browser window without ever hitting a popup blocker?
No.

if you want the parent window to close when a new page opens, why not just open the new page in the same window?? O_o

I agree with Matt, why would you go all that trouble just for the logout. If you're worried about the back button on the browser, why don't you just put security measures on your pages like checking for sessions/cookies that you set when you login. If their sessions/cookies expire then warn the users and ask them log back in. Most if not all websites with logins do the same thing and they dont have problems with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.