Don't force visitors to your webpage to listen to your music. That will just cause them to click away from your website and never return. Using the techniques described in this article you can put a music "off switch" on your webpage.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Put a Music Off Switch on Your Webpage

You've just learned how easy it is to configure a background sound for your webpage, and you think it's golly gee wiz amazing. You force visitors to your webpage to listen to your favorite music because you thinks it's the best thing since the invention of apple pie.

Visitors to your webpage are very interested in the important information that your webpage provides. Unfortunately they think the music is annoying. Which of the actions below do you think they will take to stop the annoying music?

1. Reconfigure their computer's sound application's volume setting.
2. Unplug their computer's speakers.
3. Quickly click away from your website and never return.

If you answered number 3, at least you are not a total idiot. You probably have just not yet figured out how to put a music "off switch" on your webpage. I'm going to help you with that right now.

The first thing you need to do is to remove that <BGSOUND> tag from your webpage and replace it with an <embed> tag. This allows you to provide your visitors with much more control over the music. Below is an example of an <embed> tag.

<embed autostart="true" loop="true" src="sugarplumfairy.mp3" width=100 height=100>

This code causes the music file "sugarplumfairy.mp3" to start playing when your webpage loads and to repeat the music in a loop. But unlike the <BGSOUND> tag, this code displays the user's default music player application's controls on the webpage. With Internet Explorer that would be Windows Media Player Controls in most cases. Now your visitor has the option to turn the music off.

Maybe you don't want to display those controls on your webpage. You just want a simple on/off switch. The code below displays two little radio buttons on your webpage. The user can turn the music off and on by clicking on the radio buttons.

<table bgcolor="#00ff00" border=1>
<tr><td>Music</td></tr>
<tr><td>On<input type="radio" name="sound" value="on"
  checked onClick="Play(this.value)">
<br>Off<input type="radio" name="sound" value="off"
  onClick="Play(this.value)">
<br></td></tr>
</table>
<span id="music"><embed autostart="true" loop="true" 
src="sugarplumfairy.mp3" width=0 height=0></span>

Note that the code above puts the embed tag inside a span with the id="music".

Music
On
Off

In order for the radio buttons to work, you need to paste the following code inside the <head> section of your webpage.

<script language="JavaScript">
function Play(set)
{
   if(set == "on")
   {
      document.getElementById("music").innerHTML = 
"<embed autostart='true' loop='true'
src='sugarplumfairy.mp3' width=0 height=0>";
   }
   else
   {
      document.getElementById("music").innerHTML = 
"<embed autostart='false' loop='false'
src='popups/sugarplumfairy.mp3' width=0 height=0>";
   }
}
</script>

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269