website promotion banner
eturnkeys
Your Ad Here
Web Programming  Home Web Programming JavaScript How to Make Background Music in JS
rss

How to Make Background Music in JS

Author: iCe More by this author


1. Do an IFRAME, iframe src: music.htm

If you don't know how to make i frames, read this: Iframes Basics

2. Make new htm doc.

Write in it this code in <head>:

<bgsound id="PlayMusic">
<script type="text/javascript">
<!--
PlayMusic.src="music.mp3";
function OnOff() {
   if (PlayMusic.src=="")
   {
   PlayMusic.src="music.mp3";
   OnOffButton.value="Stop";
   } else {
   PlayMusic.src="";
   OnOffButton.value="Play";
   }
}
// -->
</script>

replace the file name in "music.mp3". its not must be mp3, its can be MID or WAV, but the best is MP3 or MID.
now, in the <body> but this:

<input type="button" name="OnOffButton" value="Stop" onClick="OnOff()">

and save it as "music.html
the html shod look loke this:

<html>
<head>
<bgsound id="PlayMusic">
<script type="text/javascript">
<!--
PlayMusic.src="music.mp3";
function OnOff() {
   if (PlayMusic.src=="")
   {
      PlayMusic.src="music.mp3";
      OnOffButton.value="Stop";
   } else {
      PlayMusic.src="";
      OnOffButton.value="Play";
   }
}
// -->
</script>
</head>
<body bgcolor="#000000" scrollamount="0">
<input type="button" name="OnOffButton" value="Stop" onClick="OnOff()">
</body>
</html>

Now, u have a web site background music without flash!!!



Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "How to Make Background Music in JS"