By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,773 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,773 IT Pros & Developers. It's quick & easy.

Key interrupts

P: n/a
I would like to interrupt particular key strokes on a webpage, e.g. CTRL S
and have a javascript function called much like I can do this:

<body onclick="alert('Hello World')">

Only it would be triggered by CTRL S and calls a function of mine.
What would be the syntax? for this? Thanks.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Simon Wigzell" <si**********@shaw.ca> wrote in message
news:uUlXd.609711$Xk.154555@pd7tw3no...
I would like to interrupt particular key strokes on a webpage, e.g. CTRL S
and have a javascript function called much like I can do this:

<body onclick="alert('Hello World')">

Only it would be triggered by CTRL S and calls a function of mine.
What would be the syntax? for this? Thanks.


<
http://groups-beta.google.com/group/...0ec21127b52c26 >

CTRL wont work, afaik, but shift will:
http://www.js-examples.com/syntax/key_codes.php

--
juglesh
Jul 23 '05 #2

P: n/a
To start with you will have to write an event handler for the
onKeyDown/onKeyUp/onKeyPress event. Choosing which depends on what all
controls you have in the page.
You could do this for the entire body of the page by having an
onKeyPress="javascript:myEventHandler()"
attribute in the <body> tag.
Inside the myEventHandler() function, you could check for the
event.keyCode variable to check for the key pressed. You could also use
event.ctrlKey and event.shiftKey to check the state of the ctrl, shift
keys. They are booleans.
juglesh, wont event.ctrlKey work?
I had a requirement of disabling ctrl+n in one of my apps, and i was
able to do it.

Thanks

Anand

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.