Avatar for Username

Αναζήτηση στην υποστήριξη

Προσοχή στις απάτες! Δεν θα σας ζητήσουμε ποτέ να καλέσετε ή να στείλετε μήνυμα σε κάποιον αριθμό τηλεφώνου ή να μοιραστείτε προσωπικά δεδομένα. Αναφέρετε τυχόν ύποπτη δραστηριότητα μέσω της επιλογής «Αναφορά κατάχρησης».

Learn More

Javascript: hidden embed tag doesn't respond to Play()

  • 2 απαντήσεις
  • 3 έχουν αυτό το πρόβλημα
  • 1 προβολή
  • Τελευταία απάντηση από CJMonk

more options

In the following code snippet on Firefox (Mac OS), the Play() function is not found/does nothing.

<script> function EvalSound(soundobj) {

 var thissound=document.getElementById(soundobj);
 thissound.Play();

} </script>

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

<form> <input type="button" value="Play Sound" onClick="EvalSound('sound1')"> </form>

The <embed> tag is non-standard, but the above code works on Windows (IE, Chrome, Firefox) + Mac (Safari + Chrome).

A workaround is to give the <embed> tag attributes height=1 width=1 (resulting in a single pixel showing). Setting either height + width=0 or hidden=true seems to hide the DOM object from Javascript.

Security feature? Optimization?

In the following code snippet on Firefox (Mac OS), the Play() function is not found/does nothing. <script> function EvalSound(soundobj) { var thissound=document.getElementById(soundobj); thissound.Play(); } </script> <embed src="success.wav" autostart=false width=0 height=0 id="sound1" enablejavascript="true"> <form> <input type="button" value="Play Sound" onClick="EvalSound('sound1')"> </form> The <embed> tag is non-standard, but the above code works on Windows (IE, Chrome, Firefox) + Mac (Safari + Chrome). A workaround is to give the <embed> tag attributes height=1 width=1 (resulting in a single pixel showing). Setting either height + width=0 or hidden=true seems to hide the DOM object from Javascript. Security feature? Optimization?

Όλες οι απαντήσεις (2)

more options

Does it work if you place the embed in a DIV container that has display:none or visibility:hidden ?


A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.
The helpers at that forum are more knowledgeable about web development issues.
You need to register at the mozillaZine forum site in order to post at that forum.

See http://forums.mozillazine.org/viewforum.php?f=25

more options

Placing the embed in a hidden div container also breaks Play().

As far as I can tell, the <embed> must be visible.