Page 3


This page has two sounds, triggered by, respectively, a button and an image, that use JavaScript to play the sound.

The sound players are still embedded, but the embedding and the playing of the sounds are accomplished with JavaScript. The JavaScript functions are specified in an external file (named 'sounds.js') on the server and are not displayed when the user views the page source.

Furthermore, only part of the file name for each sound file actually appears in the page source. The full file name is assembled by JavaScript but the user never sees it. This means it is no longer very easy for the casual user to capture your sound files.

Although there is an embedded player for each sound, we have made it invisible by giving it zero height and width. So now there is nothing to right-click. I believe this will prevent owners of QuickTime Pro or similar players from easily saving your files to their computers.


We start with a simple greeting ...

Peace be unto you.


and then in Arabic ...

السلام عليكم

 

 

The polite reply is ...

And unto you be peace.


Which in Arabic is ...


 
و عليكم السلام

 

Back to amstest homepage.




Notes


  1. Two lines of HTML are required for each sound.
    For the button:
     <script>EmbedSound("fwas01vr","sound1")</script>
     <button type="button" onClick="PlaySound('sound1')">Listen</button>

    or, for the image:
     <script>EmbedSound("fwas02vr","sound2")</script>
     <img src="ear_icon.gif" onClick="PlaySound('sound2')">

    In each case, the first line generates the embedded player by calling the custom JavaScript function EmbedSound(). In this function, the first argument, "fwas01vr" is the base file name for the audio file. Inside the function, the protected subdirectory name, "prot/", and the extension, ".mp3", are appended to create the full file name: "prot/fwas01vr.mp3". The second argument, "sound1", is an arbitrary but unique (within the page) id that ties the particular embedded player (with its associated audio file) to the button or image that serves as its trigger.
    The second line of HTML defines the button or image to be used as a trigger; note that a mouse click calls the custom JavaScript function PlaySound() whose argument is the unique id that identifies the correct embedded player.
     
  2. Here is the custom Javascript file, 'sounds.js':
    /* * * * * * * * * * *
     * 
     * Javascript functions for embedding and playing sound files in a web page.
     * 
     *     by	George Saxton,  March 2011
     * 
     * * * * * * * * * * */
     
      
      function EmbedSound(filename,id) {
        if (!document.getElementById(id)) {
          // Create a new embedded sound.
          embed = document.createElement("embed");
          embed.setAttribute("src", "prot/"+filename+".mp3");
    //    embed.setAttribute("hidden", "true");	// This attr makes the Button fail!
          embed.setAttribute("height", "0");	// So we hide the element by
          embed.setAttribute("width", "0");		// giving it zero height & width.
          embed.setAttribute("autostart", "false");
          embed.setAttribute("enablejavascript", "true");
          embed.setAttribute("id",id);
          document.body.appendChild(embed);
        }
      }
      
    
      function PlaySound(soundid) {
        var sound = document.getElementById(soundid);
        sound.Play();
      }