...

View Full Version : Javascript:playsound(0) not working on chrome



var5an1
11-28-2012, 10:53 PM
I have this code below, but does not work on google chrome, please can you help to play javascript:playsound(0) on google chrome.

Code below:


<html>
<head>
<!--CSS-->
<style type="text/css">
body {background:#000000; margin-left: 0cm; margin-top: 0cm;}
img {border:none}
p{color: #FFFF00; font-weight: bold;font-family: "Courier New"; font-size: 210%; margin-left: 0.5cm; margin-bottom: 0cm}
p.ans{color: #FFFF00; font-weight: bold; font-family: "Courier New"; font-size:170%}
p.right{color: #FFFF00; font-weight: bold; font-family: "Courier New"; font-size: 170%; text-align: right; margin-right: 1cm;}
p.show{color: #000000; font-weight: bold; font-family: "Courier New"; font-size: 170%; text-align: left; margin-right: 0cm;}
td.ans{color: #FFFF00; font-weight: bold; font-family: "Courier New"; font-size: 170%}
input.ans{color: #FFFF00; background:#000000; border:0; font-weight: bold; font-family: "Courier New"; font-size: 100%; margin-bottom: 0cm}
a {text-decoration: none}
</style>
<!--Javascript for sound-->
<script type="text/javascript">

var aySound = new Array();
// Below: source for sound files to be preloaded
aySound[0] = "ding.wav";

// DO NOT edit below this line
document.write('<BGSOUND ID="auIEContainer">')
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload()
{
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else
{
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else
{
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play)
{
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound)
{
if (window.auCon) auCon.control(whSound,true);
}
function stopSound(whSound)
{
if (window.auCon) auCon.control(whSound,false);
}
</script>
<!--Change Font (Default as Blank-->
<script type="text/javascript">
var total2;
total2 = 0;
function changeColor1(obj, clr)
{
document.getElementById(obj).style.color=clr;
total2 = total2 + 41 ;
document.getElementById("mainTotal").value = total2;
}
function changeColor2(obj, clr)
{
document.getElementById(obj).style.color=clr;
total2 = total2 + 36 ;
document.getElementById("mainTotal").value = total2;
}
function changeColor3(obj, clr)
{
document.getElementById(obj).style.color=clr;
total2 = total2 + 17 ;
document.getElementById("mainTotal").value = total2;
}
function changeColor4(obj, clr)
{
document.getElementById(obj).style.color=clr;
total2 = total2 + 4 ;
document.getElementById("mainTotal").value = total2;
}
function changeColor5(obj, clr)
{
document.getElementById(obj).style.color=clr;
total2 = total2 + 2 ;
document.getElementById("mainTotal").value = total2;
}
</script>
<!--Disable Right Click-->
<script>
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler()
{
return false;
}
function mousehandler(e)
{
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
</script>
</head>
<body link="black" alink="black" vlink="black">
<br><br><br><br>
<table>
<tr>
<td><p>Name a vegetable that is not Green?</p></td>
</tr>
</table>
<br><br><br>
<table>
<tr>
<td>
<p class = "ans">&nbsp;1.</p>
</td>
<td>
<a href="javascript:playSound(0);" onClick="changeColor1('show1', '#FFFF00');">
<p class = "show">
<span id="show1" align="right">Sweetcorn...................41</span>
</p>
</a>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<p class = "ans">&nbsp;2.</p>
</td>
<td>
<a href="javascript:playSound(0);" onClick="changeColor2('show2', '#FFFF00');">
<p class = "show">
<span id="show2" align="right">Carrot......................36</span>
</p>
</a>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<p class = "ans">&nbsp;3.</p>
</td>
<td>
<a href="javascript:playSound(0);" onClick="changeColor3('show3', '#FFFF00');">
<p class = "show">
<span id="show3" align="right">Potatoes....................17</span>
</p>
</a>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<p class = "ans">&nbsp;4.</p>
</td>
<td>
<a href="javascript:playSound(0);" onClick="changeColor4('show4', '#FFFF00');">
<p class = "show">
<span id="show4" align="right">Cauliflower..................4</span>
</p>
</a>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<p class = "ans">&nbsp;5.</p>
</td>
<td>
<a href="javascript:playSound(0);" onClick="changeColor5('show5', '#FFFF00');">
<p class = "show">
<span id="show5" align="right">Radish.......................2</span>
</p>
</a>
</td>
</tr>
</table>
<br><br><br>
<table>
<tr>
<td>
<p class = "show">&nbsp;7.</p>
</td>
<td>
<p class = "ans" >&nbsp;&nbsp;Total..................<td class="ans"><input type="text" id="mainTotal" value="00" size="3" maxlength="3" class="ans"></td>
</p>
</a>
</td>
</tr>
</table>
<a href="Links.html"><img src="black.jpg"></a>
</body>
</html>

felgall
11-29-2012, 01:16 AM
1. Wrap your code in code tags (the # symbol above the input field) to make it easier to read.

2. That script is for IE4 and Netscape 4 whicl use a lot of completely different code from more modern browsers so there is no surprise that it doesn't work in browsers that have come into existance in the 10 years since the browsers that code was for died out.

3. Don't put JavaScript code in an href attribute unless the intention is for people to right click on it and save the script to their bookmarks menu to run against anybody's pages - anything belonging to your page should be attached using an event handler or an event listener instead so that it will actually work when the event occurs.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum