473,839 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

event.shiftKey is not detected in Fire fox

27 New Member
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 10258
acoder
16,027 Recognized Expert Moderator MVP
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 Recognized Expert Moderator MVP
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
rakeshvthu
27 New Member
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 Recognized Expert Moderator MVP
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
rakeshvthu
27 New Member
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 Recognized Expert Moderator MVP
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
rakeshvthu
27 New Member
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
25 New Member
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 Recognized Expert Moderator MVP
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
18747
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
16106
by: datactrl | last post by:
Hi, all Is that possible to fire a "tab" key press event with javascript? jack
2
1401
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; ----------------8<------------------------------------------ function editor_event(objname,runDelay) {
2
3088
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 cross-browser. In
5
2598
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 is the code for this. the onclick event calls a javascript function which I put an alert in the firt line to tell me if its working. It does work in IE. Any ideas on how to get netcrap... oops, I'm sorry, netscape to fire the onclick event? ...
0
1848
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 BUTTON that open the Hyperlink in a new window for a Web application. I just want to capture the Shift click event and prevent it from opening a new page. Mouse Wheel didn't pose any problems but the other mouse buttons seems to ignore the...
1
1961
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 BUTTON that open the Hyperlink in a new window for a Web application. I just want to capture the Shift click event and prevent it from opening a new page. Mouse Wheel didn't pose any problems but the other mouse buttons seems to ignore the...
6
14219
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 get keycode vs event types. http://www.w3.org/2002/09/tests/keys-cancel2.html
4
7065
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 except when Alt+Shift is pressed. For example, the charCode alt+shift+a does not reflect a capitalized a, 'A', or alt+shift+1 does not reflect '!', instead they should 'a' and '1', respectively. Furthermore, I found that when alt+shift is pressed, the...
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10908
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10649
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7829
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7018
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4487
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.