HighDots Forums  

Capturing Ctrl N

Javascript JavaScript language (comp.lang.javascript)


Discuss Capturing Ctrl N in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bilal
 
Posts: n/a

Default Capturing Ctrl N - 06-02-2004 , 05:08 AM






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

Reply With Quote
  #2  
Old   
Pedro Graca
 
Posts: n/a

Default Re: Capturing Ctrl N - 06-02-2004 , 05:28 AM






Bilal wrote:
Quote:
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

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :


Reply With Quote
  #3  
Old   
Ivo
 
Posts: n/a

Default Re: Capturing Ctrl N - 06-02-2004 , 06:27 AM



"Bilal" wrote
Quote:
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




Reply With Quote
  #4  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Capturing Ctrl N - 06-02-2004 , 06:43 AM



"Pedro Graca" wrote:
Quote:
Bilal wrote:
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
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.




Reply With Quote
  #5  
Old   
R. Rajesh Jeba Anbiah
 
Posts: n/a

Default Re: Capturing Ctrl N - 06-02-2004 , 10:08 AM



bjeewa (AT) hotmail (DOT) com (Bilal) wrote in message news:<f9882c89.0406020108.7ad3bdfe (AT) posting (DOT) google.com>...
Quote:
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.
Sometime ago, we had a similar discussion
<http://groups.google.com/groups?selm=abc4d8b8.0311212053.4be98d39%40posting .google.com>

In short, in PHP there is no "direct" way of trapping the "Ctrl+N"
as it is server-side.

--
Quote:
Just another PHP saint |
Email: rrjanbiah-at-Y!com


Reply With Quote
  #6  
Old   
Jim Ley
 
Posts: n/a

Default Re: Capturing Ctrl N - 06-02-2004 , 12:07 PM



On Wed, 2 Jun 2004 10:43:48 +0000 (UTC), "Richard Cornford"
<richard (AT) litotes (DOT) demon.co.uk> wrote:

Quote:
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.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/



Reply With Quote
  #7  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Capturing Ctrl N - 06-02-2004 , 01:19 PM



Jim Ley wrote:
Quote:
Richard Cornford wrote:
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?
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.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.