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 Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

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 type="audio/mpeg" src="sugarplumfairy.mp3" width="100" height="100" autostart="true" loop="true">

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 type="audio/mpeg" src="sugarplumfairy.mp3" autostart="true" loop="true" 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 type='audio/mpeg' src='sugarplumfairy.mp3' autostart='true' loop='true' width='0' height='0'>";
   }
   else
   {
      document.getElementById("music").innerHTML = "<embed type='audio/mpeg' src='sugarplumfairy.mp3' autostart='false' loop='false' width='0' height='0'>";
   }
}
</script>

RSS Feed RSS Feed



Web Design Sections

Eloquent JavaScript: A Modern Introduction to Programming

Eloquent JavaScript

Eloquent JavaScript Eloquent JavaScript goes beyond the cut-and-paste scripts of the recipe books and teaches you to write code that's elegant and effective. You'll start with the basics of programming, and learn to use variables, control structures, functions, and data structures. Then you'll dive into the real JavaScript artistry: higher-order functions, closures, and object-oriented programming.

Reader Anthony says, "This book is not your typical Javascript book. Others have a utilitarian approach. In stark contrast, Eloquent JavaScript does not merely provide you a checklist of things to learn but rather paints a panorama of the possibilities that programming provides. Javascript is merely the tool used to introduce these to the reader.

Click here for more information.


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268