JavaScript Link Object : onkeydown Event handler

Description

The onkeydown event handler of a link object can be defined in a piece of text, image or predefined area. It executes some JavaScript code or function when a key is pressed down over a link object.

Version

Implemented in JavaScript 1.2

Syntax

onkeydown = "JavascriptCode"

Parameter

JavascriptCode : JavaScript statement or JavaScript function.

Example of Link object : onkeydown event handler

In the following web document onkeydown event handler executes an alert box when a key is pressed down over a link object.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>JavaScript Link Object's Event handler : onkeydown Example</title>
</head>
<body>
<h1 style="color: red">JavaScript Link Object's Event handler : onkeydown</h1>
<h3>Press tab key and focus on the link then press down a key on Google or Yahoo .... and see the onkeydown effect ....</h3>
<hr />
<form name="form1" action="#">
<a href="http://www.google.com"
onkeydown='alert("onkeydown effect on Google....")'>
Google</a>
<br />
<br />
<a href="http://www.yahoo.com"
onkeydown='alert("onkeydown effect on Yahoo....")'>
Yahoo</a>
</form>
</body>
</html>

View the example of link object's onkeydown event handler in the browser

Practice link object's onkeydown event handle with Online Editor

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also :

Javascript event handlers.

Javascript object's event handlers.

Please Google+, Like this tutorial on FaceBook, Tweet, save it as bookmark and subscribe with our Feed. Have suggestions? comment using Disqus down this page. Thanks.


share with delicious share with facebook w3r rss  share with digg share with reddit share with stumbleupon share with twitter