By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,709 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,709 IT Pros & Developers. It's quick & easy.

event.shiftKey is not detected in Fire fox

P: 27
hi all,

we have a requirement to disable shift click and ctrl click.

i have code:

Expand|Select|Wrap|Line Numbers
  1. document.onmousedown = shiftEnter;
  2.  
  3. function shiftEnter(e) {
  4.  if (event.shiftKey) {
  5.  alert("shift key is disabled");
  6.  return false;
  7.  }
  8. }
  9.  
this code is not working in Fire fox, please help.

thanks,
rakesh.
Jan 31 '08 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

Moderator.
Jan 31 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Browsers besides IE would use the 'e' while IE uses the global window.event.

For a cross-browser solution, use something like:
Expand|Select|Wrap|Line Numbers
  1. if (!e) var e = window.event;
then e will refer to the event.
Jan 31 '08 #3

P: 27
Browsers besides IE would use the 'e' while IE uses the global window.event.

For a cross-browser solution, use something like:
Expand|Select|Wrap|Line Numbers
  1. if (!e) var e = window.event;
then e will refer to the event.
Thanks for quick reply but It doesnt worked, can you suggest some other way of handling this, detecting event.shiftKey/event.ctrlKey events in Fire Fox.
Feb 1 '08 #4

acoder
Expert Mod 15k+
P: 16,027
Thanks for quick reply but It doesnt worked, can you suggest some other way of handling this, detecting event.shiftKey/event.ctrlKey events in Fire Fox.
What does your code look like now?
Feb 1 '08 #5

P: 27
What does your code look like now?
Expand|Select|Wrap|Line Numbers
  1.         function shiftEnter(e) {
  2.             if(navigator.userAgent.indexOf("MSIE") >= 0) { 
  3.                 if ( event.shiftKey || event.ctrlKey ) {
  4.                     alert("MSIE");
  5.                   var msg = "<bean:message key='home.player.operationNotAllowed' />";
  6.                   alert(msg);
  7.                    return false;
  8.                 }
  9.             } else if(navigator.userAgent.indexOf("Firefox") >= 0) {
  10.                 if(!e){
  11.                     alert("Fire fox");
  12.                     var e = window.event;
  13.                     if( e.shifyKey || e.ctrlKey ){
  14.                       var msg = "<bean:message key='home.player.operationNotAllowed' />";
  15.                       alert(msg);
  16.                        return false;
  17.                     }
  18.                 }
  19.             }
  20.         }
  21.  
My code looks like this, please inform if anything wrong.
Feb 1 '08 #6

acoder
Expert Mod 15k+
P: 16,027
Yes, there's no need for browser detection. Try this:
Expand|Select|Wrap|Line Numbers
  1. function shiftEnter(e) {
  2.     if (!e) var e = window.event;
  3.     if (e.shiftKey || e.ctrlKey ) {
  4.       var msg = "<bean:message key='home.player.operationNotAllowed' />";
  5.       alert(msg);
  6.       return false;
  7.     }
  8. }
Feb 2 '08 #7

P: 27
Yes, there's no need for browser detection. Try this:
Expand|Select|Wrap|Line Numbers
  1. function shiftEnter(e) {
  2.     if (!e) var e = window.event;
  3.     if (e.shiftKey || e.ctrlKey ) {
  4.       var msg = "<bean:message key='home.player.operationNotAllowed' />";
  5.       alert(msg);
  6.       return false;
  7.     }
  8. }
Sorry it is not working :( , is there any other different way to solve this problem.
Feb 4 '08 #8

kvijayhari
P: 25
hi the following code worked nicely for me both in ie and firefox...

Expand|Select|Wrap|Line Numbers
  1. <script language=javascript>
  2. document.onmousedown = shiftEnter;
  3. function shiftEnter(e) {
  4.     if (!e) var e = window.event;
  5.     if (e.shiftKey || e.ctrlKey ) {
  6.           var msg = "<bean:message key='home.player.operationNotAllowed' />";
  7.             alert(msg);
  8.             return false;
  9.        }
  10. }
  11. </script>
there is no reason the code shouldn't work for u..

do u get any errors or warnings??

if s please post the error or warning u r getting..
Feb 4 '08 #9

acoder
Expert Mod 15k+
P: 16,027
It works for me in Firefox. Can you post the rest of your code (if it's not too much). Maybe something else is affecting the script.

Edit: Thanks kvijayhari. You posted before I managed to finish typing.
Feb 4 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.