How to I make my browser beep from JavaScript [like Toolkit.beep() in Java]?

Jayesh Nazre

There is no direct function for beeping in JavaScript. But you can use applets for the same. I have included a button in the applet. When you click it the beep sound will come. If you do not want a button in the applet then just do not include it. Use a input type=button and in its clicked event call the Java function beep() I have written.

The HTML Code :


<html>
<head>
<script language=javascript>
function test() {

document.musicApp.beep();

}
</script>
</head>
<body>


<form name=frm_test id=frm_test>
<input type=button value=BEEPJScript onclick=test()>
</form>


<applet code="Beep.class" width=100 height=100
NAME="musicApp" MAYSCRIPT>

</body>
</html>
The Java code :

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Beep extends Applet implements ActionListener {
  Button b;

  public void init() {
    b = new Button ("BEEPJava");
    b.addActionListener (this);
    add(b);
  }

  public void actionPerformed (ActionEvent ae) {
    this.beep ();
  }

  public void beep() {
    this.getToolkit().beep();
  }
}
NOTE: If you do not want the applet to be shown in your HTML then do not add the button to the applet and make the width and height in the html code to "0" for the applet tag.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact