473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

window.close() not working in IE

snowdonkey
Hello! I'm having difficulty closing a popup window in Internet Explorer.

In the script below playButton and stopButton are images that when clicked, should open a popup window and close it, respectively. audioFile is a URL to an mp3.

Right now the new window will open when playButton is clicked, but will not close when stopButton is clicked. I don't get any error messages. Thanks for your help!

function audioOnOff(audioFile, playButton, stopButton)
{
var audioWindow;

playButton.attachEvent("onclick", playAudio);
stopButton.attachEvent("onclick", stopAudio);

function playAudio()
{
audioWindow = window.open(audioFile, "_blank");
}

function stopAudio()
{
audioWindow.close();
}
}
Aug 3 '06 #1
2 22320
Banfa
9,065 Expert Mod 8TB
your variable audioWindow is declared in the scope of audioOnOff. That means it only exists for the length of time that function is running so by the time you get to calling stopAudio is is no longer the same instance of the variable and doesn't correspond to the opened window.

I would also not declare playAudio and stopAudio inside audioOnOff so I would declare it this as

Expand|Select|Wrap|Line Numbers
  1. var audioWindow;
  2.  
  3. function playAudio()
  4. {
  5.         audioWindow = window.open(audioFile, "_blank");
  6. }
  7.  
  8. function stopAudio()
  9. {
  10.        audioWindow.close();
  11. }
  12.  
  13. function audioOnOff(audioFile, playButton, stopButton)
  14. {
  15.        playButton.attachEvent("onclick", playAudio);
  16.        stopButton.attachEvent("onclick", stopAudio);
  17. }
  18.  

You may also need to do something for the case of the user clicking a play button when a window is already open as you will end up with 2 windows open but audioWindow will only refer to the last window opened.
Aug 4 '06 #2
Ah, makes sense. Very kind for the heads-up on replacing the pop-ups windows. Thank you very much for your help!
Aug 4 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: J P Singh | last post by:
Hi Guys Wonder if someone can help me with this. I have a form where a user clicks a button which gives them a pop up windows to allow them to add the data. The user adds the data and click...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
9
by: Justin Koivisto | last post by:
Is there a way to create an alert-like message box that uses a custom image? Basically, I want to replace the default ! image with something else. -- Justin Koivisto - spam@koivi.com PHP...
3
by: Martin | last post by:
Hi, this is probably a very basic question but I'm not a javascript expert! Sure you get this asked often! Did some research but can't get it working. I'm thankful for any help! Thanks! ...
3
by: Asit | last post by:
<META HTTP-EQUIV="expires" content="0"> <META HTTP-EQUIV="pragma" content="no-cache"> <html> <head> <title>Fidelity NetBenefits</title> </head> <body BGCOLOR="#ffffff"> <script...
2
by: RWC | last post by:
Hello, I am new to JavaScript but until now, have felt my way along fairly successfully. I have a page showing an image to the user. I use window.open to open a separate page, listing a bunch...
7
by: Drew Berkemeyer | last post by:
Hello, We have an application that we have written using ASP.NET. On one of our pages we open a popup window using javascript. The popup window has a save and a cancel button. Both of them are...
14
by: Paul | last post by:
Hi I have 2 functions in java script, one opens a second window-this works, the other is supposed to close this second window, does not seem to be working. Just wondering if anyone had any ideas....
5
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any...
3
by: Laurahn | last post by:
The function javascript:window.close() is not working in firefox. how do i close browser window in firefox.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.