Event Listeners and Objects
This section provides a quick description of event trigger attributes on different HTML tags and the 'event' object representing the event with detail information about the event. A tutorial example is provided to display mouse location by adding a listener to the mouse-pushed-down event.
IE browser also supports special HTML attributes to let you add event listeners and passing event objects.
Here are few commonly used HTML attributes on various HTML tags:
- "<body onLoad="listener_code" ...>" - The specified listener code will be executed when the "onLoad" event
is triggered by the browser starting to load the HTML document.
- "<body onMouseDown="listener_code" ...>" - The specified listener code will be executed
when the "onMouseDown" event is triggered by the user pushing down the mouse button anywhere in the browser window.
- "<a onMouseOver="listener_code" ...>" - The specified listener code will be executed
when the "onMouseOver" event is triggered by the user moving mouse over this hyper link.
- "<input type="button" onClick="listener_code" ...>" - The specified listener code will be executed
when the "onClick" event is triggered by the user clicking this button.
More event trigger attributes will be introduced in other chapters in this book.
To illustrate some nice features of event triggers, I wrote this VBScript tutorial example:
- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
<title>Event Listener and Trigger</title>
window.alert("Mouse pushed down!")
<body onMouseDown="mouseDown()" language="vbscript">
<p>Click anywhere on the page to see a message.</p>
In this tutorial example, the "onMouseDown" event trigger attribute on the "body" tag
is used to add a short listener code to be executed when the user push down the mouse button
on the page.
A message is reported back to the user with an alert box by calling the "alert()" method
on the "window" object. See the picture below:
Table of Contents
About This Book
Introduction of VBScript - Visual Basic Scripting Edition
Variant Data Type, Subtypes, and Literals
Numeric Comparison Operations and Logical Operations
String Operations - Concatenation and Comparison
Variable Declaration and Assignment Statement
Expression and Order of Operation Precedence
Statement Syntax and Statement Types
Array Data Type and Related Statements
Array References and Array Assignment Statements
Conditional Statements - "If ... Then" and "Select Case"
Loop Statements - "For", "While", and "Do"
"Function" and "Sub" Procedures
Inspecting Variables Received in Procedures
Error Handling Flag and the "Err" Object
Regular Expression Pattern Match and Replacement
scrrun.dll - Scripting Runtime DLL Library
Creating Your Own Classes
►IE Web Browser Supporting VBScript
VBScript Support in IE Web Browsers
Including VBScript Codes with HTML "script" Tags
Including VBScript Codes as External Files
DOM API - The "document" Object
DOM API - The "window" Object
►Event Listeners and Objects
'vbscript:' Pseudo-URL Addresses
IIS ASP Server Supporting VBScript
WSH (Windows Script Host)
PDF Printing Version