spacer
Yehuda Shiran November 24, 1999
Hot Keys
Tips: November 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

We'll use the term hot key to describe a key that executes a specific action on a Web page. For example, we could write a script that takes the user to Microsoft's front page whenever the user presses the key "M" on the page. Take a look at the following script::

<SCRIPT LANGUAGE="JavaScript1.2">
<!--

var NS = (window.Event) ? 1 : 0;

function checkKey(e) {
  var code = (NS) ? e.which : event.keyCode;
  var key = String.fromCharCode(code);
  for (var i = 0; i < ar.length; i++) {
    if (key == ar[i].key) location.href = ar[i].url;
  }
}

function hotKey(key, url) {
  this.key = key;
  this.url = url;
}

if (NS) document.captureEvents(Event.KEYPRESS)
document.onkeypress = checkKey;

var ar = new Array();
ar[ar.length] = new hotKey("h", "http://www.docjs.com/");
ar[ar.length] = new hotKey("m", "http://www.microsoft.com/");
ar[ar.length] = new hotKey("n", "http://www.netscape.com/");

// -->
</SCRIPT>

As you can see, it is possible to assign as many hot keys as you wish. Each key can be associated with a different Web page. Note that your hot keys will operate on Internet Explorer 4.0x, Navigator 4.0x, and above. Older browsers will ignore them. For more information about keyboard events, refer to Column 9, The Navigator Event Model, Column 10, The Internet Explorer Event Model, and Column 11, The Cross-Browser Event Model.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business