2

Possible Duplicate:
Playing sound with JavaScript

I'm making a javascript chat for my site and I need to play a sound when it has a new message and the chat is not focused, just like the Facebook's chat. Problem is I have no clue how to play this sound in background with javascript. Could you help me?

Edit: Crossbrowser solutions without Flash will be better

Community
  • 1
  • 1

2 Answers2

8

You may use jQuery and it's append function along with script;

Create an element (example - <div>) or use an existing element, and give it some id (like <div id="some_div">). Then try the below code

$('#some_div').append('<embed id="embed_player" src="your_sound_file.wav" autostart="true" hidden="true"></embed>');

Hope this helps... :)

Alfred
  • 20,303
  • 60
  • 160
  • 239
1

A quick search of relevant tutorials should get you on your way. If you encounter any problems, feel free to ask about those specific issues rather than a broad subject.


Is it possible to use this tag without the browser rendering a player?

Yes it is. Just don't add the controls attribute. That's what makes it show up, so if you leave it out the player won't be there.

Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566