473,387 Members | 2,436 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,387 software developers and data experts.

WindowsXP and Javascript to play a sound on a page

On most my pages, I use Javascript to play a sound. It works fine in
Netscape 4.7, Netscape 7.2, Firefox 1.0, IE5 and IE6 using Windows98 as
the operating system. However, using WindowsXP as the operating system,
the entire Netscape 7.2 browser and Firefox 1.0 browser shuts down when
I try to use the Back button on these pages. Is there some setting in
Windows XP that is causing this or is there something I can add to the
Javascript to prevent this from happening?

Here's a sample page - http://keyserfan.home.mindspring.com/millers.htm

Thanks,
Keyser
Jul 23 '05 #1
2 2152


Keyser wrote:
On most my pages, I use Javascript to play a sound. It works fine in
Netscape 4.7, Netscape 7.2, Firefox 1.0, IE5 and IE6 using Windows98 as
the operating system. However, using WindowsXP as the operating system,
the entire Netscape 7.2 browser and Firefox 1.0 browser shuts down when
I try to use the Back button on these pages. Is there some setting in
Windows XP that is causing this or is there something I can add to the
Javascript to prevent this from happening?

Here's a sample page - http://keyserfan.home.mindspring.com/millers.htm


That page doesn't use JavaScript "to play a sound", it simply does a
document.write for an <embed src="somefile.wav"> so that the browser
loads a plugin to play the sound if a plugin is available.
I have tried that page with Windows XP, Firefox 1.0 and the Quicktime
plugin 6.0 set up to play audio/wav files and I have no problems going
to another page and then back to the page.
You haven't told us which plugin you are using.

As for the script in that page it looks as follows (:

<SCRIPT language=JavaScript>
<!-- Original: Kipp W. Shinabarger ([snipped email here]) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) || (OPER>-1)) {
document.write("<BGSOUND SRC=sounds/rumpus2.wav >");
} else {
document.write("<EMBED SRC=sounds/rumpus2.wav AUTOSTART=TRUE ");
document.write("HIDDEN=true VOLUME=100");
}
// End -->
</SCRIPT>

so you should clean that up, the closing > for the embed is missing e.g.
you need

document.write('<EMBED SRC="sounds/rumpus2.wav" AUTOSTART="TRUE" ');
document.write('HIDDEN="true" VOLUME="100">');

though you might better use a single document.write call e.g.

document.write('<EMBED SRC="sounds/rumpus2.wav" AUTOSTART="TRUE" ' +
'HIDDEN="true" VOLUME="100">');

And all those HTML comments <-- --> have in my view no place inside of a
script element, beside one such comment wrapper around the whole script
code for historical reasons if you want, so you should throw the
comments out respectively use JavaScript comment syntax if you need to
cite where the script comes from e.g.
// This script and many more are available free online at ...

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Thanks for the reply.

I obtained this script from javascript.internet.com many, many years
ago, and I just left in the comments from the original author, mostly to
ensure that he gets the credit for it.

Quicktime is the plug-in called.

I think the issue may be with the security settins in Windows XP on my
PC at work. I recently got a PC with WindowsXP (we've been running
Windows98 also for many years). It only happens at work, not at home,
where I'm still running Windows98. The same thing happens on another
friend's page who uses the same script.

I'll make the changes suggested.

Thanks again,
Keyser
Martin Honnen wrote:


Keyser wrote:
On most my pages, I use Javascript to play a sound. It works fine in
Netscape 4.7, Netscape 7.2, Firefox 1.0, IE5 and IE6 using Windows98
as the operating system. However, using WindowsXP as the operating
system, the entire Netscape 7.2 browser and Firefox 1.0 browser shuts
down when I try to use the Back button on these pages. Is there some
setting in Windows XP that is causing this or is there something I
can add to the Javascript to prevent this from happening?

Here's a sample page - http://keyserfan.home.mindspring.com/millers.htm

That page doesn't use JavaScript "to play a sound", it simply does a
document.write for an <embed src="somefile.wav"> so that the browser
loads a plugin to play the sound if a plugin is available.
I have tried that page with Windows XP, Firefox 1.0 and the Quicktime
plugin 6.0 set up to play audio/wav files and I have no problems going
to another page and then back to the page.
You haven't told us which plugin you are using.

As for the script in that page it looks as follows (:

<SCRIPT language=JavaScript>
<!-- Original: Kipp W. Shinabarger ([snipped email here]) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) || (OPER>-1)) {
document.write("<BGSOUND SRC=sounds/rumpus2.wav >");
} else {
document.write("<EMBED SRC=sounds/rumpus2.wav AUTOSTART=TRUE ");
document.write("HIDDEN=true VOLUME=100");
}
// End -->
</SCRIPT>

so you should clean that up, the closing > for the embed is missing
e.g. you need

document.write('<EMBED SRC="sounds/rumpus2.wav" AUTOSTART="TRUE" ');
document.write('HIDDEN="true" VOLUME="100">');

though you might better use a single document.write call e.g.

document.write('<EMBED SRC="sounds/rumpus2.wav" AUTOSTART="TRUE" ' +
'HIDDEN="true" VOLUME="100">');

And all those HTML comments <-- --> have in my view no place inside of
a script element, beside one such comment wrapper around the whole
script code for historical reasons if you want, so you should throw
the comments out respectively use JavaScript comment syntax if you
need to cite where the script comes from e.g.
// This script and many more are available free online at ...

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gil | last post by:
I'm trying to write a page that allows me to change the background midi that's playing. I've been going crazy consulting Google Groups, and coming up with ingenious solutions, some of which kind...
2
by: laredotornado | last post by:
Hello, I had been given this code to play a single sound file embedded in a page. Sadly, the code doesn't actually "play" any sound file. Could you help supply some JS code that will play a sound...
1
by: cbell | last post by:
I would like javascript file (which can be a .js file) which I can use to play .wav files on demand. there are many pages and there will only be ONE .wav file (about 20 seconds) for each page. ...
1
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be"...
9
by: outstretchedarm | last post by:
How exactly does HTML/Javascript handle playing midi files? Does it have a player imbedded in it? Or does it borrow from the computer's midi player? How could you make a webpage play certain...
3
by: illmagination | last post by:
Hi, I recently received a task to have a .wav file play only once when home page is 1st loaded and only play again when the user re-visits the page by opening a new browser. I am using...
19
by: Tony | last post by:
I'm working on project that plays movies using Windows Media Player and I'm controlling everything with JavaScript. Per the client I only need to support IE 6 or greater which happens to make...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
8
by: Mateusz Viste | last post by:
Hi, I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.