473,387 Members | 1,592 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.

Firefox Annoyance (keyboard event)

Jezternz
145 100+
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.preventDefault(); 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 3200
Jezternz
145 100+
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 Expert 100+
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 Expert Mod 4TB
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 100+
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 Expert 100+
@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 Expert Mod 4TB
you may have a look here for a quick comparison of different frameworks ...

kind regards
Jan 12 '09 #7
Jezternz
145 100+
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 Expert 100+
@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
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...
14
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...
6
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...
2
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
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...
13
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.