JavaScript - An open source scripting language, it allows the creation of dynamic web page content.  Home Web Programming JavaScript How to Make Background Music in JS
Your Ad Here

How to Make Background Music in JS


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!!!



Author's URL: iCe
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More JavaScript Tutorials at LearnPHP.org

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

Only registered users can write comment

No comments yet...