Capturing Ctrl N

B

Bilal

Hi,
Is there any way to capture the action Ctrl+N (whether it in a hidden
button or keyword - doesn't matter) in html, javascript or php? I
appreciate any suggestions.
Thank you and kind regards
Bils
 
P

Pedro Graca

Bilal said:
Is there any way to capture the action Ctrl+N (whether it in a hidden
button or keyword - doesn't matter) in html, javascript or php? I
appreciate any suggestions.


HTML: no
PHP: no
JavaScript: I have no idea
 
I

Ivo

Is there any way to capture the action Ctrl+N (whether it in a hidden
button or keyword - doesn't matter) in html, javascript or php? I
appreciate any suggestions.

Asking if such things are possible in any other language than client side
script, shows a great lack of understanding. I tried (in IE6) the following
<script type="text/javascript">
onkeydown=keyd;
function keyd(e) {
e=e||window.event;
k=String.fromCharCode(e.keyCode).toLowerCase();
if( k=="n" && e.ctrlKey) alert('Nnnn');
if( k=="o" && e.ctrlKey) alert('Oooh');
if( k=="l" && e.ctrlKey) alert('Lalala');
return false;
}
</script>
but only get the alert for L and O, not for N. I guess there 's a reason for
that.
You don't say what you want the ctrl+N for. If it is to stop people opening
new windows while on your site, please reconsider. There are always ways to
bypass any script you write and restore normal browser behaviour.
HTH
Ivo
 
R

Richard Cornford

Pedro Graca said:
HTML: no
PHP: no
JavaScript: I have no idea

In javascript the answer is yes and no. In IE, for example, if contents
of the document have focus (so are receiving keyboard input) then it is
possible to intercept Ctrl+N, but if the window has focus the keystrokes
go straight to the browser and scripts running in the document never get
to hear about them. Gecko browsers seem to allow all keystrokes to be
intercepted (though not necessarily cancelled) and Opera browsers tend
to keep their keyboard shortcuts entirely to themselves. So on the whole
it is probably not worth the effort to try to detect Ctrl-N as the
effort will predictably fail at least often enough to fail to address
whatever motivates the question.

The result of Ctrl-N in Windows IE is to open a new browser instance
(with full chrome) and showing the same page/URL as the old one (and
associated with the same user session), so the reason for asking this
question is usually a realisation that such an action will have harmful
consequences for a server-side system. But this is normal behaviour form
web browsers (and unavoidable) so the solution is to fix the server-side
code so that it can cope with the normal behaviour of client browsers.

Richard.
 
J

Jim Ley

Gecko browsers seem to allow all keystrokes to be
intercepted (though not necessarily cancelled) and Opera browsers tend
to keep their keyboard shortcuts entirely to themselves.

Er, so you can guess where people navigate too if they type in the
URL?

Jim.
 
R

Richard Cornford

Jim said:
Er, so you can guess where people navigate too if they
type in the URL?

In principle I suppose you could, though it was some considerable time
ago I was testing this and there have been a lot of Mozilla releases in
the meanwhile (so it may no longer be true). And I didn’t try
specifically capturing keystrokes aimed at the location bar because I
was experimenting to see if there was any way of preventing the use of
bookmarked javascript URLs so removing the location and menu bars from
the window was the obvious first barrier to their use.

I remember at the time thinking that it was poor that Mozilla was
letting a script within a document intercept and cancel keyboard
shortcuts.

Richard.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top