Changing Background music randomly by Javascript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Embed

Description

Changing Background music randomly by Javascript

Demo Code

ResultView the demo in separate window

<html lang="en">
   <body translate="no">     
      <script>
var Song = [];//from ww w. ja v  a2 s .  c om
Song[0] = "Song/Song1.mp3";
Song[1] = "Song/Song2.mp3";
Song[2] = "Song/Song3.mp3";
Song[3] = "Song/Song4.mp3";
Song[4] = "Song/Song5.mp3";
Song[5] = "Song/Song5.mp6";

var idx = Math.round( Math.random() * 5 );

document.write("<embed src='"+Song[idx]+"' autostart=true hidden=true loop=true'>");

    
      </script>  
   </body>
</html>

Related Tutorials