1. The code is very short. You can play small audio files in WAV format. Please give your advice and don't laugh at me. Sound is the file name
- Function play (sound)
- {
- If (navigator. appname = "Microsoft Internet Explorer ")
- {
- VaR snd = Document. createelement ("bgsound ");
- Document. getelementsbytagname ("body") [0]. appendchild (SND );
- SND. src = sound;
- }
- Else
- {
- VaR OBJ = Document. createelement ("object ");
- OBJ. width = "0px ";
- OBJ. Height = "0px ";
- OBJ. type = "audio/X-WAV ";
- OBJ. Data = sound;
- VaR body = Document. getelementsbytagname ("body") [0];
- Body. appendchild (OBJ );
- }
- }
Instance:
- <HTML>
- <Head>
- <SCRIPT>
- Function play (sound)
- {
- If (navigator. appname = "Microsoft Internet Explorer ")
- {
- VaR snd = Document. createelement ("bgsound ");
- Document. getelementsbytagname ("body") [0]. appendchild (SND );
- SND. src = sound;
- }
- Else
- {
- VaR OBJ = Document. createelement ("object ");
- OBJ. width = "0px ";
- OBJ. Height = "0px ";
- OBJ. type = "audio/X-WAV ";
- OBJ. Data = sound;
- VaR body = Document. getelementsbytagname ("body") [0];
- Body. appendchild (OBJ );
- }
- }
- </SCRIPT>
- </Head>
- <Body>
- <Input type = "button" id = "test" onclick = "play('gold.wav ');" value = "test sound">
- </Body>
- </Html>