/    Sign up×
Community /Pin to ProfileBookmark

Calling a function to Play() audio isnt working

Hello, I have been having this problem. I am trying to get this function to work. What its suppose to do is play a sound without and event handler(onclick, onload) just trying to call the function. I used Error Console to try and help me, all I got from that is ‘Error calling method NPObject! Line 9’ Line 9 is this code: soundLogout.Play();

Here is the rest of my code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script type=”text/javascript”>
function playSound(logoutSound) {
var soundLogout=document.getElementById(logoutSound);
soundLogout.Play();
}
</script>
</head>
<body>

<embed src=”logout.wav” autostart=”false” id=”logout” enablejavascript=”true”/>

<script type=”text/javascript” language=”javascript”>
if(document.getElementById(‘logout’)){
playSound(‘logout’);
}
</script>
</body>
</html>

One thing I noticed, if you put an alert message inbeween the variable line and the Play() inside the function it works! but then I have an alert message (which i dont want), that code looks like:

<script type=”text/javascript”>
function playSound(logoutSound) {
var soundLogout=document.getElementById(logoutSound);
alert(logoutSound);
soundLogout.Play();
}
</script>

Any Help would be awesome Thanks

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @jsuske spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...