Tricky Tricks ›› Programming Tricks ›› Javascript Tricks ›› Playing Music Automatically When A Page Is Displayed

Playing Music Automatically When A Page Is Displayed

Javascript Tricks

Playing music automatically when a page is displayed:

Here is the standard little JAVA script that figures out whether you are using Netscape or Internet Explorer. IE uses the <BGSOUND> while Netscape uses the <EMBED> tag. Here are things to make sure of when installing this:

  • Be careful about your choice of selection. Music means different things to different people. What you consider a nice happy tune, may be the song somebody heard while their spouse asked for a divorce or something. Also keep in mind that it can scare people a bit!
  • Make sure you keep the document.writeln all in one piece. It is a long line, but do not split the line.
  • Test with Netscape. If it does not work, make sure your server is configured for MIME audio/x-midi. In otherwords, tell your system administrator that you want to play music!
  • Get yourself a MIDI file that you like.

<SCRIPT LANGUAGE="JavaScript">
<!--
if(navigator.userAgent.indexOf("MSIE") != -1)
document.writeln ('');
else
document.writeln ('<EMBED SRC="full_loop.mid" AUTOSTART="true" HIDDEN="true" VOLUME="80%">');
//-->
</SCRIPT>
<BGSOUND SRC="full_loop.mid">

Partners