/    Sign up×
Community /Pin to ProfileBookmark

Closing Popup when Opener window is gone

Hello,

How can I close a popup window when the main window which created the popup is closed or main window moves to another page ? I need to do this thru an event handler.

Thanks,
Raktims

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJan 14.2003 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<script type="text/javascript">

<!--

var win;

function newWin(url) {

win = window.open(url,'','height=300,width=200');

window.onunload = function() {if (!window.closed) window.close()};

return false;

};

// -->

</script>

<title>Example</title>

<p><a href="http://www.w3.org/" onclick="return newWin(this.href)">W3C</a></p>[/font]
Copy linkTweet thisAlerts:
@raktimsauthorJan 14.2003 — Thanks for your reply.

I am getting a problem with the code. When I close the main window a Windows dilaog box pops up to confirm if I want to close the popup window. On saying 'yes' the focus goes to the popup and it stays open. What could be wrong.
Copy linkTweet thisAlerts:
@CharlesJan 14.2003 — [font=georgia]I screwed up and should have posted:[/font]

[font=monospace]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<script type="text/javascript">

<!--

var win;

function newWin(url) {

win = window.open(url,'','height=300,width=200');

window.onunload = function() {if (![b]win[/b].closed) [b]win[/b].close()};

return false;

};

// -->

</script>

<title>Example</title>

<p><a href="http://www.w3.org/" onclick="return newWin(this.href)">W3C</a></p>[/font]
Copy linkTweet thisAlerts:
@raktimsauthorJan 14.2003 — Great. Thanks. I came up with the fix at the same time. Appreciated.

raktims
×

Success!

Help @raktims spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...