Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

The JavaScript FAQ
Prev Home Next

Stopping Sound

Question: How do I write a JavaScript function that stops playing sound?

Answer: If you've opened a separate sound control window using the code self.location="AUDIO_FILE_URL" (see Example 1), then there is no simple way to stop the sound programmatically. The user will have to close the sound control window manually.

To be able to stop playing sound from JavaScript, you'll need to use the techniques described in Example 2.

Let's assume that Microsoft Internet Explorer is playing the sound file mySound.mid specified by the BGSOUND tag
<BGSOUND ID="BGSOUND_ID" SRC="mySound.mid">
To stop playing the sound, you can use this code:
document.all['BGSOUND_ID'].src='jsilence.mid'
Here jsilence.mid is a "do-nothing" sound file - it does not play any sound at all.

Now assume that Netscape Navigator is playing the sound mySound.mid specified by the following EMBED tag:

<EMBED NAME="mySound" SRC="mySound.mid" 
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>
Then you can use the following code to stop the playback:
document.mySound.stop()

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


 
 
  Mirrored with kind permission of Alexei Kourbatov Design by Interspire