Previous Example-|-Next Example-|-Return to Chapter Listing

Example 12.13:
onerror: Setting onerror for the Window

[This example works with Netscape Navigator 3. It will not work with Internet Explorer 3.]

The button below would normally create a JavaScript error, because it calls a function that doesn't exist. However, we've added an onerror script handler for this window, setting onerror to null; that is, suppressing all JavaScript errors. This is not a very dramatic demonstration, because when you click the button...nothing happens. However, look at the source code and you'll see that we're trying to call the run() function, which doesn't exist...and which, therefore, should create an error.


In the HEAD we have this simple script: <SCRIPT> <!-- window.onerror=null //--> </SCRIPT> In the BODY of the page we have this button tag: <form> <input name="error" type="button" value="Click Here to Create Error" onclick="run()"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing