Question about "Beep" or Alert in JavaScript

IM Not programimng any WebSite, its for a PC software.
I have a software with free code, so what i bassicly what i wants is when “RegisterEvent(EVENT_GAMEMSG, quitfunc)” happens, goes to quitfunc

And quitfunc is:

function quitfunc(msg, type)
case 2:
if(msg.indexOf(msg) != -1){

In (HERE MUST COME AND ALERT CODE) should replace with an Alert Code or a Beep Code or something
Any idea what i can do?
So the program does a Beep when the event happen, or maybe popout a windows alert or something?

You will need the sound in an audio file and have JavaScript add the <audio> tag to the page when you want the sound to play (and remove it again when you want the sound to stop playing).

It would be better to create a permanent AUDIO instance and then just play and pause it as required.

Because mobile devices don’t cache HTML5 media, so if you created it on the fly, it would have to reload the audio file again every time.

1 Like

Use the alert function it’s good alert( “work done” );

alert is completely different – that’s a modal dialog in which you have to click “ok”, it’s very different from just making a beep sound.

That might be want the OP wants though, not sure. If a dialog is wanted, then yeah that would be simplest. But if it’s literally just the sound, then using audio would be better.

Using console.log() is better than using alert() - it doesn’t annoy your visitors asking them if they want to disable alerts or JavaScript if you forget to remove the debugging code before your script goes live.

Not all browsers display the extra checkboxes in alerts but alerts in live pages are as dead as Netscape 4 (the last browser that didn’t support updating the web page itself) and alerts were re-purposed for debugging use then. Since console.log() replaced it there has been no use for alert whatsoever and it should be considered obsolete since you have no control over how it looks and there are many alternatives available where you do have that control.

If you need to play sound for any reason I highly recommend this library

While HTML 5 audio tags are preferred by it, it has a flash player fallback for older browsers.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.