Reply
close old popup window when opening a new one
Old 07-27-2007, 04:20 AM close old popup window when opening a new one
ice
Novice Talker

Posts: 7
Trades: 0
Hello,
im working on a page where the visitors can listen to some tunes. By clicking a button a popup window opens, which contains a player, that plays the sound.
i use the following code:

Code:
onClick="window.open(url, name, size); return false"
but when the user selects the next tune, the old one continues playing, because the window is still open. Is there a function that allows me to close the old popup as soon as a new one opens?

hope you can help me
thanks
ice is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 07-27-2007, 05:11 AM Re: close old popup window when opening a new one
tripy's Avatar
Do not try this at home!

Posts: 3,436
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
The easiest way to prevent this behaviour would not be to close/open another popup, but play every sounds in the same popup.
For that, you simply need to retrieve the popup reference upon opening it, which your code prevent now.
For that, you will need a javascript function that will act as a controller between the links and the popup.

Try this:
Code:
<script type=text/javascript">
  var popWin = false;
 
 
  function playSound(url,name,size){
    popWin = window.open(url,'popWin',size);
  }
</script>
 
<a href="javascript:playSound(url, name, size);">song 1</a>
I intentionally left the "name" parameter in the function call, but it won't be used. I made this to let the calling be more close that what you have now.


When you try to open a popup and another window(popup) have the same "name", the already opened window have it's location updated to the new url.
This will have the effect of preventing that multiple sounds are played at the same time.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-27-2007, 08:52 AM Re: close old popup window when opening a new one
Experienced Talker

Latest Blog Post:
Long time no … erm post?
Posts: 45
Name: Matthew Bagley
Trades: 0
or you could assign the popup to a variable and use the window.close method then reopen the window.

Code:
onClick="newfunctionhahaha(url, name, size);"
then in the funciton have
Code:
function newfunctionhahaha(URL, NAME, SIZE){
if (oldwindow){oldwindow.close;}
oldwindow = window.open(url, name, size);
}
I think that should work been a while since I used popups
__________________
Matthew Bagley
Paramiliar Design Studios
Who am I | Free Layouts |Website Development | UK SEO
Paramiliar is offline
Reply With Quote
View Public Profile
 
Old 07-27-2007, 09:47 PM Re: close old popup window when opening a new one
ice
Novice Talker

Posts: 7
Trades: 0
thank you both. i used the easy way to just name all the links the same and its working allright now.
cheers
ice is offline
Reply With Quote
View Public Profile
 
Old 07-28-2007, 06:36 AM Re: close old popup window when opening a new one
ice
Novice Talker

Posts: 7
Trades: 0
oops, just realised, it doesnt seem to work in ie.....
why is it?
ice is offline
Reply With Quote
View Public Profile
 
Old 07-28-2007, 06:55 AM Re: close old popup window when opening a new one
Experienced Talker

Latest Blog Post:
Long time no … erm post?
Posts: 45
Name: Matthew Bagley
Trades: 0
simple answer IE sucks, more complex answer dunno cant see the code
__________________
Matthew Bagley
Paramiliar Design Studios
Who am I | Free Layouts |Website Development | UK SEO
Paramiliar is offline
Reply With Quote
View Public Profile
 
Old 07-28-2007, 07:42 AM Re: close old popup window when opening a new one
ice
Novice Talker

Posts: 7
Trades: 0
Quote:
Originally Posted by Paramiliar View Post
simple answer IE sucks
I know
well, it works sort of, but sometimes when clicking one of the links i get a popup asking if i want to close the window....
but theres nothing i can do about it i suppose
ice is offline
Reply With Quote
View Public Profile
 
Old 07-28-2007, 08:14 AM Re: close old popup window when opening a new one
ice
Novice Talker

Posts: 7
Trades: 0
And do you know how to get the popup to allways appear at the front?
The first popup gets set in front of the main window, but as soon as i click a new link, it disappears to the back. I need it to come back to the front as soon as its loaded, or allways stay at the front.
I tried:


Code:
 <a href="preview.html"
onClick="self.blur();window.open('preview.html','name','size').focus; return false;">
-> opens the link in the same window and not a popup anymore

and
Code:
<body onBlur="this.focus()">
and
Code:
<body onBlur="window.focus()">
the last two dont make any difference at all, the window still stays at the back of the mother window

im a bit confused.....
can anyone help?

Last edited by ice; 07-28-2007 at 08:49 AM.. Reason: some additions
ice is offline
Reply With Quote
View Public Profile
 
Old 07-28-2007, 11:07 AM Re: close old popup window when opening a new one
ice
Novice Talker

Posts: 7
Trades: 0
ok, sorted.
i finally found a way to do it.
thanks for your help
ice is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to close old popup window when opening a new one
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10326 seconds with 13 queries