Jump to Real's How-to Main page

Emit a beep

The only way to make a "System Beep" with Javascript is to call the JAVA beep() function (available in JDK1.1).
<HTML>
<SCRIPT>
function beep() {
   java.awt.Toolkit.getDefaultToolkit().beep();
   }
</SCRIPT>
<BODY>
<FORM><INPUT TYPE=button VALUE="Beep" onClick="beep()"></FORM>
</BODY>
</HTML>
It's ok with Netscape but IE can only access Java method in an Applet (not the Java classes directly). The workaround is to embed the call in an Applet.
import java.awt.*;
import java.applet.*;
public class JavaBeep extends Applet{
  public void oneBeep() {
    Toolkit.getDefaultToolkit().beep();
    }
}
Then in javascript
document.JavaBeep.oneBeep();

If you find this article useful, consider making a small donation
to show your supportfor this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]