By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,711 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,711 IT Pros & Developers. It's quick & easy.

Closing a window by not being the url that opened it

P: n/a
Initial situation:

main window of the browser display url A
THEN

- user click on a link (which also opens a popup on the onClick event) to
url B
AS A CONSEQUENCE

- main window displays url B
- a popup is open


THE QUESTION IS:
================

How can close the popup window from the code of url B?
Is there a way to reference the popup window (so that you can call the close
method), although url B didn't open it?

Cheers

Daniele
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Daniele Baroncelli wrote:
How can close the popup window from the code of url B?
Is there a way to reference the popup window (so that you can call
the close method), although url B didn't open it?


When you open the popup window in document A, give it a somewhat
"unique" name (second argument of Window.open()).

In document B, you can use Window.open() with an empty string as
the first argument and that "unique" name as second argument to
get popup window referenced.

Example:

Document A
<a href="b.html" onclick="window.open('popup.html','qqwxyyp')">

Document B
function closePopup() {
var w = window.open('', 'qqwxyyp');
if (w && !w.closed) w.close();
}

ciao, dhgm
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.