Capturing Ctrl N

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bilal

    Capturing Ctrl N

    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
  • Pedro Graca

    #2
    Re: Capturing Ctrl N

    Bilal wrote:[color=blue]
    > 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.[/color]


    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 :

    Comment

    • Ivo

      #3
      Re: Capturing Ctrl N

      "Bilal" wrote[color=blue]
      > 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.[/color]

      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.eve nt;
      k=String.fromCh arCode(e.keyCod e).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


      Comment

      • Richard Cornford

        #4
        Re: Capturing Ctrl N

        "Pedro Graca" wrote:[color=blue]
        > Bilal wrote:[color=green]
        >> 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.[/color]
        >
        > HTML: no
        > PHP: no
        > JavaScript: I have no idea[/color]

        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.


        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: Capturing Ctrl N

          bjeewa@hotmail. com (Bilal) wrote in message news:<f9882c89. 0406020108.7ad3 bdfe@posting.go ogle.com>...[color=blue]
          > 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.[/color]

          Sometime ago, we had a similar discussion
          <http://groups.google.c om/groups?selm=abc 4d8b8.031121205 3.4be98d39%40po sting.google.co m>

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

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

          Comment

          • Jim Ley

            #6
            Re: Capturing Ctrl N

            On Wed, 2 Jun 2004 10:43:48 +0000 (UTC), "Richard Cornford"
            <richard@litote s.demon.co.uk> wrote:
            [color=blue]
            >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.[/color]

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

            Jim.
            --
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            • Richard Cornford

              #7
              Re: Capturing Ctrl N

              Jim Ley wrote:[color=blue]
              >Richard Cornford wrote:[color=green]
              >> 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.[/color]
              >
              > Er, so you can guess where people navigate too if they
              > type in the URL?[/color]

              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.


              Comment

              Working...