Datasheet

Chapter 1: Introduction to JavaScript
11
and properties not available in WebKit s, and vice - versa. Over time, the object models have evolved
considerably too. The first DOM (supported in Netscape 2 and Internet Explorer 3) supported only a
small fraction of what is available today. In Appendix F you can find detailed browser support data with
version information to assist you.
When to Use JavaScript
Sometimes it s useful to consider the “ big picture when looking at a new technology. Once you
understand that, you can begin to anticipate the answers to other questions that might come up. One of
those “ big picture questions for JavaScript is what can it do and what can it not do . After all, it is a
scripting language and running inside a browser (usually) we know there must be limits to its power.
Let s start with the types of things it can do :
Dynamically draw boxes, images, and text on the page: Using Dynamic HTML and the DOM,
you can arbitrarily style and animate these types of objects on a webpage.
Open and close windows: You can spawn new browser windows and communicate with them
to some degree. You can also create simulated windows using DHTML and even provide drag
and drop support for them like real windows that would appear elsewhere on the desktop.
Animate on - screen contents: You can create multiple, simultaneous, threaded animations using
DHTML, the DOM, and JavaScript timers.
Modify the document: You can create elements, text, and images, or you can delete or modify
existing ones.
Communicate with the server: Using Ajax and similar techniques, you can asynchronously
send messages back and forth between the server and the client without forcing the page to
re - load.
Talk to Java, Flash, Silverlight objects: You can even communicate with other types of media
embedded on the page to control the behavior of Flash and Silverlight movies or interface with
Java Applets.
Snoop on the user; record what they do: Yes, it s even possible (however nefarious) to record
everything your website users are doing on a page, their mouse movements, keystrokes, and so
on, and study it later. There are benign uses for this data, too (for example web analytics).
Read the mouse/keyboard: You can keep detailed track of what the user is doing with the
keyboard and mouse in order to create extremely rich and interactive web applications.
Save data offline for later: You can put information in semi - permanent storage on the user s
computer so that the next time they come to our page and want access to it, they can have it.
Create free - form graphic elements: Using complementary technologies like Canvas elements,
Scalable Vector Graphics, and Flash, you can put free - form elements on a page and even change
them on the fly.
Create accessible web pages: A common misconception is that it is not possible to have an
accessible web page for people with disabilities and still use JavaScript. Most web users with
disabilities are using browsers that do support JavaScript. Given a bit of care and attention, you
can make sure your pages are easy for them to use.
CH001.indd 11CH001.indd 11 6/25/09 7:53:19 PM6/25/09 7:53:19 PM