Results 1 to 4 of 4

Thread: Help with KeyPress

  1. #1
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Help with KeyPress

    I want to have the user redirected to another page when any key is pressed. I know this is fairly simple to do, but I cannot seem to find anything to do it.

    Thanks,
    Tim
    Last edited by TimFA; 03-14-2007 at 02:46 AM.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    <script type="text/javascript">
    document.onKeyPress = function() { window.location = "anotherpage.html" }
    </script>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <script type="text/javascript">
    document.onKeyPress = function() { window.location = "anotherpage.html" }
    </script>
    It's onkeypress, not onKeyPress: Javascript is case-sensitive. Also, using window.location like a string is a bit of a hack, and has inconsistent behaviour with other types of window (like frames). You want to provide something for non-JS browsers, too.
    Code:
    <script type="text/javascript">
      document.onkeypress = function() {
        location.href = "newpage.html";
      };
    </script>
    <noscript>
      <p>
        Please click <a href="newpage.html">here</a> to continue.
      </p>
    </noscript>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    Thank you for your help.

    Tim

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •