Forum Moderators: open
Is there something I am missing?
Any help would be appreicated.
Here is my code:
function PlayPrayerSound()
{
if(window.document.BGSound!= null)document.BGSound.Stop();
if(window.document.PrayerSound!= null)document.PrayerSound.Play();
}
Sincerly,
Justin
See if this works for you?
if(!document.getElementById('BGSound').play()){
document.getElementById('BGSound').stop();
}
if(!document.getElementById('PrayerSound').play()){
document.getElementById('PrayerSound').play();
}
I have replaced the window.document with window.getElementById, but I think the real issue you had was with the uppercase Play and Stop JavaScript is case sensitive and that functions are lowercase.
HTH,
-George
Any clues? As of now, I have it:
1319. function PlayPrayerSound()
1320. {
1321. if(!window.getElementById('BGSound').play()){
1322. window.getElementById('BGSound').stop();
1323. }
1324. if(! window.getElementById('PrayerSound').play()){
1325. window.getElementById('PrayerSound').play();
1326. }
1327. }
I tried replacing window with document and with window.document But both of those gave me an error, saying that, Document/window.document.getElementById fuction does not exist. or something like that.
Firstly the getElementById is part of the document object rather than the window. Therefore window.getElementById will not work it has to be document.getElementById.
Here is the full working example i set up local to my machine:
<html>
<head>
<script language=javascript>
function PlayPrayerSound()
{
if(!document.getElementById('BGSound').play()){
document.getElementById('BGSound').stop();
}
if(!document.getElementById('PrayerSound').play()){
document.getElementById('PrayerSound').play();
}
}
</script>
</head>
<body>
<embed src="C:\WINDOWS\Media\ringin.wav" autostart=false id="BGSound" hidden=true>
<embed src="C:\WINDOWS\Media\ringin.wav" autostart=false id="PrayerSound" hidden=true>
<a href="javascript:PlayPrayerSound()">Test sound</a>
</body>
</html>
This example uses windows sounds my path is above you will have to replace the paths above to an actual *.wav on your machine.
Let's know how you get on with that...
-George
If you are using the BGSOUND element:
<bgsound src="blah.wav" .....>
then, getElementById will not work, because 'bgsound' isn't it's id, but it's tagName.
You could try getting a reference with: document.getElementsByTagName('bgsound')[0]
but you might as well use the DOM level 0 method:
document.bgsound
..back where we started. Try this..
Ok, after further investigations, I have noticed this is the tag it has:
<EMBED NAME=BGSound HIDDEN=TRUE SRC="sound/anxiety4.mp3" VOLUME="-500" LOOP="FALSE" AUTOSTART="TRUE">
<EMBED NAME=PrayerSound HIDDEN=TRUE SRC="prayers/anxiety4.mp3" VOLUME="-500" LOOP="FALSE" AUTOSTART="FALSE">
With that, should I change the current Embed tags? or should I change the Javascript to fit those current embeded tags.
Thanks for all the help,
Justin
I need some sleep so I can't answer fully
With that, should I change the current Embed tags? or should I change the Javascript to fit those current embeded tags.
Perhaps that's a matter of preference.
Very likely, you can't reference the tag because it has a name attribute, not id. My preference would be to put in id attributes (same as name). Then try again:
var sound1 = document.getElementById('BGSound ')
etc
Put the element into a global var like that so it's easier to get at.
Hopefully that works. If not, check up on the methods available to the element. Here you go:
Goodnight!