0

How to Play Notification Sound using JQuery

last days when i was working on a chat app my client said to me to play a notification sound whenever a user receive new message from another user.I implemented this in a simple chat box application using Jquery and HTML5 audio tag, it is just five lines of code.check below :

HTML :

Here i created a UL tag to append all my messages in it.Then used an input with onkeydownevent so user can type a message and fire it with ENTER key.And the inportant audio tag with my audio sound so i can play it.

JavaScript :

In javascript i made the function process_chat().In this function i just checked if user pressed the ENTER key (with keycode event) then we will process for next work.Later in this script i got the value of input and appended that in our UL tag.After doning this i just used jquery’s play() function to play my audio file.

Hope it will Help You and please subscribe me and like my facebook page :

and make me proud.By the way if you face any problem then let me know in comment section below

Leave a Reply

Your email address will not be published. Required fields are marked *