Key interrupts

S

Simon Wigzell

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.
 
J

juglesh

Simon Wigzell said:
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...7b52c26?q=onKeyPress+juglesh#f90ec21127b52c26 >

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

c.anandkumar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top