Closing a window by not being the url that opened it

D

Daniele Baroncelli

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
 
D

Dietmar Meier

Daniele said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top