Jump to content

Embedded Audio File always plays on load - even with autoplay off


Jimmy12

Recommended Posts

Hi,

i have the following code:

where i want the sound to only play during the false part of the IF statement

but currently it always plays on every reload, and even if the IF = true

any ideas? ive tried autoplay="0" also

 

Thanks

 

	<embed src="beep.wav" autostart="false" width="0" height="0" id="sound1"
enablejavascript="true">

+

<script>
function PlaySound(soundObj) {
  var sound = document.getElementById(soundObj);
  sound.Play();
}
</script>

+

		if( isset( $json['Data'] ) ){
			echo "<b>Success</b>";
			echo "</br>";
			echo $data.' x ' .$tqty;  
			echo "</br>";
			
		} else {
			echo "Error";
			echo "</br>";
			echo $json['Message'];
			echo '<script> PlaySound("Sound1"); </script>';
		}

 

Link to comment
Share on other sites

2 hours ago, gw1500se said:

It is playing because you are telling it to in the echo/script. If you want the user to start the play, create a button instead and have the onClick attribute execute the PlaySound script.

yes though the echo/script should only run when the 2nd part of the IF statement is initiated.

I dont want the user to start anything - more of an alert when an error occurs

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.