|
|
|
|
|
|
|
Chapter 4: Objects and Events
The objects you can use in VBScript are among the most powerful features available to the language. And because these objects can respond to events, they're even more useful. This chapter takes a look at VBScript's objects and the events they can handle. Accessing an object property This example accesses the Window object's title property, which exposes the title contained in the browser's title bar. Page 37. JavaScript version Accessing an object method Many objects also support methods, which are special functions that perform actions. The write method of the document object is such a function. Page 38. JavaScript version Handling events Events are things that happen to an object and VBScript makes it easy to handle these events in special blocks of code called, appropriately enough, event handlers. Pages 39-40. (No JavaScript version: See next example) Creating an inline event handler In addition to dedicated event handler blocks, like those used in the previous example, you can also create inline event handlers, which can be useful if you have a lot of events to handle on a page. (Note: This version is slightly more elegant than the version in the book). Page 41. JavaScript version Handling events with subroutines You can also handle events with dedicated subroutines. Sadly, the example in the book is a little off, so I've fixed it here. Page 42. (No JavaScript version: See previous example) |
|
|
| All content © 1997-1999 Paul Thurrott |