/    Sign up×
Community /Pin to ProfileBookmark

Close Window Code

Hello,
My question is concerning this website: [URL=”http://www.jstreet.org”]http://www.jstreet.org[/URL]
If you go here and click on “Click here for playlist,” you will get a pop-up window with a Finetune.com playlist. The concern with this pop-up is, people no longer need to keep the jstreet.org site open to listen to that playlist. Is there a JavaScript code that can close a pop-up window when the original site’s main window is closed? This will assure that the jstreet.org window stays open while a user listens to the playlist.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@Wisest_GuyNov 15.2007 — [CODE]var Win = window.open(...);
window.onunload = function(){Win.close();}[/CODE]
Copy linkTweet thisAlerts:
@visual84authorNov 15.2007 — Great!...now if you can tell me where I might place this in my html, I'll be set! Also, right now I have the pop-up opening with a behavior, do I need to change this?
Copy linkTweet thisAlerts:
@Wisest_GuyNov 15.2007 — You can put this anywhere in your page that opens the popup window, just make sure you assign the window to a variable when you create it.
[code=html]
<SCRIPT>
window.onunload = function(){
if (WhateverVariableYourPopupIs){WhateverVariableYourPopupIs.close();}
}
</SCRIPT>
[/code]
Copy linkTweet thisAlerts:
@visual84authorNov 15.2007 — You can put this anywhere in your page that opens the popup window, just make sure you assign the window to a variable when you create it.
[code=html]
<SCRIPT>
window.onunload = function(){
if (WhateverVariableYourPopupIs){WhateverVariableYourPopupIs.close();}
}
</SCRIPT>
[/code]
[/QUOTE]


I'm not sure what you mean by assign it to a variable. Sorry, I'm not too familiar with code yet. And will I need to change the behavior I have assigned to the link?
Copy linkTweet thisAlerts:
@Wisest_GuyNov 15.2007 — Change this:
[CODE]
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
[/CODE]

To this:
[CODE]
function MM_openBrWindow(theURL,winName,features) { //v2.0
PlaylistWindow = window.open(theURL,winName,features);
}
window.onunload = function(){
if (PlaylistWindow){PlaylistWindow.close();}
}
[/CODE]
Copy linkTweet thisAlerts:
@visual84authorNov 16.2007 — It worked! Thanks for your help! I hope you don't mind if I ask you for help in the future.
×

Success!

Help @visual84 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...