473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

event.shiftKey is not detected in Fire fox

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
9 10230
acoder
16,027 Expert Mod 8TB
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
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
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
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
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
16,027 Expert Mod 8TB
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

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

Similar topics

5
by: Matthew | last post by:
Is there anyway to tweak this to ignore the function() only if the Tab key is pressed? onkeydown="javascript:function();"
6
by: datactrl | last post by:
Hi, all Is that possible to fire a "tab" key press event with javascript? jack
2
by: znndrp | last post by:
Hi all, I've got a function that captures a keypress event. This is working fine, but in some cases I want to fire the same even again but with different parameters. Example; ...
2
by: jhcorey | last post by:
Right now I have code like this which works in IE (this fires on an onclick): function f_Click(x) { if (window.event.shiftKey) { I'd like to find the simplest way to make this work...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
0
by: lechatthierry | last post by:
Is it possible to block a mouse event on an Hyperlink with a general script event? This is quite troublesome for me. I am trying to find a way to block the windows shortcut SHIFT + MOUSE LEFT...
1
by: Neko | last post by:
Is it possible to block a mouse event on an Hyperlink with a general script event? This is quite troublesome for me. I am trying to find a way to block the windows shortcut SHIFT + MOUSE LEFT...
6
by: mingchin.AT | last post by:
Hi, In Javascript, the simple way to check user input is to get the keycode. But for cross browser, its seems we need to have two different keycodes for the same key. There is a web page for...
4
by: hui11 | last post by:
Hi, According to the doc at mozilla, http://developer.mozilla.org/en/docs/DOM:event.charCode, the charCode takes shift into consideration when pressed. I found that to be true for other cases...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.