Before you go any further, think hard: Do you really want to do this? Background sounds have a way of annoying people. There someone is, happily surfing the net, when suddenly their computer starts playing music for everyone to hear, perhaps everyone in the office area, who are now finding out that our formerly happy surfer isn't really working. That's not to say that background sounds are never a good idea... you may have noticed that we use one on this page. It just seemed appropriate for a page about sounds on web pages.
Now, assuming you've thought through the consequences of your actions, let's talk about how to put a background sound on your page. Unfortunately the browser industry and standards committees have not settled on a standard way of accomplishing this. Netscape allows background sounds through use of the
<EMBED ...>
<BGSOUND ...>
<EMBED ...>
<BGSOUND ...>
With this
<SCRIPT TYPE="text/javascript"> <!-- var filename="hazy_shade_of_winter.mid"; if (navigator.appName == "Microsoft Internet Explorer") document.writeln ('<BGSOUND SRC="' + filename + '">'); else if (navigator.appName == "Netscape") document.writeln ('<EMBED SRC="' + filename + '" AUTOSTART=TRUE WIDTH=144 HEIGHT=60><P>'); // --> </SCRIPT> <NOSCRIPT> <BGSOUND SRC="hazy_shade_of_winter.mid"> </NOSCRIPT>The code says this:
- If the current browser is MSIE then write out a
tag.<BGSOUND ...>
- Else, if the current browser is Netscape then write out an
tag.<EMBED ...>
- Then in the
section, browsers that don't understand scripting will see the<NOSCRIPT>
tag. Several browsers that don't understand scripting do understand<BGSOUND ...>
. Also, browsers that have scripting turned off but do understand<BGSOUND ...>
will also see this tag. Of course, browsers that have scripting turned off but don't understand<BGSOUND ...>
will have no sound at all. Again, that's the price being paid for lack of standards. At least they won't fail with an ugly error message.<BGSOUND ...>
Tidak ada komentar:
Posting Komentar