admin管理员组

文章数量:1308604

I found the following answer, but it does not seem to work in an HTML page:

console.log('\u0007');

How I trigger the "System Bell" in nodejs

Is there a way to ring the system bell from Javascript?

Chrome OSX

I found the following answer, but it does not seem to work in an HTML page:

console.log('\u0007');

How I trigger the "System Bell" in nodejs

Is there a way to ring the system bell from Javascript?

Chrome OSX

Share Improve this question edited May 23, 2017 at 12:07 CommunityBot 11 silver badge asked Feb 10, 2013 at 21:41 B SevenB Seven 46k73 gold badges256 silver badges400 bronze badges 1
  • This answer has a function to make a simple javascript beep() – Hellonearthis Commented Jan 11, 2017 at 8:03
Add a ment  | 

2 Answers 2

Reset to default 5

The answer you linked to works for Node because Node's console.log writes to the standard output of the process. It's actually the system's terminal emulator that sees the BEL character and makes a beep. (No different than if you put a BEL in a file and ran cat on that file.)

Since browser script does not have access to standard output, you're out of luck.

However, you could use the <audio> tag to play a sound of your choice.

You can't. Imagine how annoying that would be... I could do this, for example:

console.log(new Array(100000).join('\x07'));

And you'd get 99999 beeps.

本文标签: Is it possible to ring the system bell with JavascriptStack Overflow