473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Firefox Annoyance (keyboard event)

Jezternz
145 New Member
I came across a very interesting problem recently. Basicly I am building an editor and I want to take advantage of hot keys. I got it working perfectly in Internet Explorer, But I hit problems when I tried in Firefox, stranger still I found Chrome worked fine.

The problem is the use of hotkeys that are already used in firefox. In my example I have used Ctrl-S (Save page in both FF and Ch). Now I would think evt.preventDefa ult(); would be the answer, unfortunately this does not work in ff (does in chrome though?).

I have later found, It will work but only when its a <input> or other form control with the event handler. I think this is a bit sad, anyway around it?

Expand|Select|Wrap|Line Numbers
  1.     var keydownfunc = function(e){
  2.         if(!e)e=window.event;
  3.  
  4.         if(window.event){e.returnValue = false;e.cancelBubble = true;}
  5.         else {e.preventDefault();e.stopPropagation();}    
  6.  
  7.         if(e.ctrlKey && e.keyCode == 83)
  8.             alert('Save Doc now');
  9.         document.focus();
  10.     }
  11.  
  12.     window.addEventListener?
  13.      document.addEventListener('keydown',keydownfunc,false)
  14.       :document.attachEvent('onkeydown',keydownfunc);
  15.  
Also note straight away I thought of google docs, soon found out the problem actually occurs in google doc's just the same.

Thanks. Josh
Jan 9 '09 #1
8 3224
Jezternz
145 New Member
I was looking at some other onkeydown event things, and I found that on quirksmode, the test app that was made, did supress the Ctrl-S. So I looked into the code and all I had to do from the start was simply return false in the handler :(

source: JavaScript - Detecting keystrokes

Im quite relieved actually, thought IE had an upper there for a while, dont understand why google docs does not use this though :S

Anyway, thanks for any time anyone put in, Josh
Jan 9 '09 #2
xNephilimx
213 Recognized Expert New Member
Use jquey, it will save you an incredible ammount of time.
jQuery: The Write Less, Do More, JavaScript Library
Jan 9 '09 #3
gits
5,390 Recognized Expert Moderator Expert
you could even use another JS-framework of course ... but to understand what those frameworks do for you and for what they are good for ... you should have such problems as you had ;) ... and know the solutions. to use a framework like jQuery, dojo, qooxdoo or whatever ... you should really need some more research regarding the things you really need or that you expect that you will need ... i'm not saying that jQuery is a bad recommendation but there are a lot of frameworks out there that might fullfill some different needs ...

kind regards
Jan 9 '09 #4
Jezternz
145 New Member
I am working on an editor, and it will likely turn out to be alot of script. So I am not sure if I want to run more script with a framework? Would a framework like Jquery add much loadtime / download time?
Jan 9 '09 #5
xNephilimx
213 Recognized Expert New Member
@Jezternz
Not at all, jQuery is a really lightweight javascript framework, you can download it packed, so it's really compressed, too. Frameworks like prototype + scriptaculous are kind of heavier, but nothing to worry about. you see, the vast majority of the sites use some javascript framework, and it really doesn't slow them down.
I use jQuery, because to me, is the smallest one, faster to learn, really flexible, and extensible.
Jan 12 '09 #6
gits
5,390 Recognized Expert Moderator Expert
you may have a look here for a quick comparison of different frameworks ...

kind regards
Jan 12 '09 #7
Jezternz
145 New Member
After looking into jQuery it looks truely amazing. I have a couple of questions about it though.
First what is the license like? Can you use your code (with the framework) commercially?
Secondly, just how efficient is it? will this add loading times or delays to your average user?
Thirdly, is it a good idea to commit to the JQuery framework, ie, will they be around for a while longer? are they reliable? (opinion off course)
Jan 12 '09 #8
xNephilimx
213 Recognized Expert New Member
@Jezternz
Take a look at the link gits posted, great resource to compare js frameworks.

- jQuery can be used commercially, there's no problem about it. http://docs.jquery.com/Licensing

It's the lightest js framework available.

They are truly reliable, his foundator (John Resig) is currently working with mozilla org, developing the upcoming js specification and working on the engine too.
Jan 13 '09 #9

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

Similar topics

9
2128
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE and Safari, but in the latest FireFox I get no title or article, but do see the prev and next links and the article number. My HTML and JS simple routine is as follows:
14
23274
by: xxbmichae1 | last post by:
I have a <select> object that i've set up an onchange event that fires in IE fine when I use the cursor up and down in the list, but If I use the cursor up and down in Firefox the event doesn't seem to fire until I've left the field....If i use the mouse all is fine, only when using the cursor keys does it not fire the onchange event in FF. Thanks for any help in advance.
6
14909
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function keypress() {
2
1801
by: Hillage | last post by:
Hi, It's possible to disable then online help in Firefox when I press F1 key, using 'onkeypress' or 'onkeydown' event? Thanks in advance, S. Hillage
2
3020
by: Astra | last post by:
Hi All I have a JS routine to prohibit users from entering a range of chars in a textbox and although this works perfectly in IE x, in the latest version of Firefox it appears to be blocking keys that I want to allow. The routine sort of still works, but its as if the mapping of the keys is worked out completely differently. I thought the key maps would be universal. My code is as follows:
13
1434
by: Flomo Togba Kwele | last post by:
For some reason, using Ctrl-leftarrow or Ctrl-rightarrow does not move the cursor in VS2005. Opening the same VB file in Notepad, this function works by skipping (or reverse skipping) to the next word. Is this the way it's supposed to work, or have I mangled some option? Thanks, Flomo
4
7790
by: jonathandrott | last post by:
Hi, i'm kinda new to vb.net and i'm trying to make an on screen keyboard to use with a touch screen. how do i get it to print a letter on the screen when the button is pressed in the textbox that is selected? do i do it as a ascii character? i'm trying to get data from a user. there are a couple of different field the user will have to type information into. (i.e. first name, last name, .etc)
0
9594
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
10599
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
10347
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
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.