Skip to Content
Dynamic HTML: The Definitive Reference
book

Dynamic HTML: The Definitive Reference

by Danny Goodman
July 1998
Intermediate to advanced
1456 pages
65h 5m
English
O'Reilly Media, Inc.
Content preview from Dynamic HTML: The Definitive Reference

Examining Mouse Buttons and Key Codes

The next code listing, Example 6.3, further demonstrates how to access event object properties in both browsers, even when the properties don’t match up well. In this case, a script displays information about mouse clicks and key presses in the status bar, to limit the disruption of the user. For mouse clicks over a button, this laboratory application presents the identifying integer for the mouse button used to do the click. For key presses in a text area, the application displays the character code value of the key typed by the user.

Example 6-3. Looking for Mouse Button and Keyboard Character Codes

<HTML> <HEAD> <TITLE>Button Codes / Key Codes</TITLE> <SCRIPT LANGUAGE="JavaScript"> var isNav, isIE if (parseInt(navigator.appVersion) >= 4) { if (navigator.appName == "Netscape") { isNav = true } else { isIE = true } } function showBtnOrKey(evt) { var theBtnOrKey if (isNav) { theBtnOrKey = evt.which } else { if (window.event.srcElement.type == "textarea") { theBtnOrKey = window.event.keyCode } else if (window.event.srcElement.type == "button") { theBtnOrKey = window.event.button } } status = theBtnOrKey return false } </SCRIPT> </HEAD> <BODY> <H1>Mouse Button and Key Codes from Event Objects</H1> <HR> <FORM> <P>Click on this <INPUT TYPE="button" VALUE="Button" onClick="showBtnOrKey(event)"> with either mouse button (if you have more than one).</P> <P>Enter some text with uppercase and lowercase letters:<BR> <TEXTAREA COLS=30 ROWS=4 onKeyPress="showBtnOrKey(event)" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Dynamic HTML: The Definitive Reference, 3rd Edition

Dynamic HTML: The Definitive Reference, 3rd Edition

Danny Goodman

Publisher Resources

ISBN: 1565924940Catalog PageErrata