Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Doing something when a key is pressed

    Hi

    We have a web blocking unit at the office, which shows a blocking web page when someone accesses porn etc.

    The following code is on the page which either opens outlook to send an email or tries to access a url when a key is pressed. e for outlook or r to retry and access the page.

    Code:
    document.onkeydown=function(keyPressed){
      if(keyPressed.which == 69)  { 
      window.location="mailto:support@company.com?subject=%U %r %i"
      return false;
      } else if (keyPressed.which == 82) { 
                window.location="%U"
    				return false;
    			}
    		}
    THis works great in firefox and safari but not IE. Can anyone point me in the right direction to what could be wrong?

    note: %U %i %r are variables from our web blocking unit for Url, IP and reason why page was blocked.

  • #2
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Btw in IE I get the error message 'which' is null or not an object

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    The function's argument is not the key pressed, is the event itself. IE and Mozilla have different models of capturing the events and different models to handle the key events:
    Code:
    <script type="text/javascript">
    document.onkeydown=function(e){
    !e?e=window.event:null;
    var code=e.keyCode?e.keyCode:e.which;
    if(code==69){window.location='mailto:support@company.com?subject=&#37;U %r %i';return false}
    if(code==82){window.location='%U';return false}
    }
    </script>
    Quote Originally Posted by bryanwebster
    e for outlook or r to retry and access the page.
    Do you think all the people use Outlook by all means? I, for instance, use Thunderbird
    Last edited by Kor; 10-13-2008 at 12:26 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    bryanwebster (10-13-2008)

  • #4
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hey thanks for that! I am new to javascript (only just picked up a book yesterday) and I guess I was way off track?

    Quote Originally Posted by Kor View Post
    Do you think all the people use Outlook by all means? I, for instance, use Thunderbird
    LOL true, I try to avoid Outlook as well but all the office staff use it that is why I defaulted to saying Outlook instead of "their default email client"

    But thanks again for the help it is much appreciated!


  •  

    Posting Permissions

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