How to stop web pages from hijacking a keyboard using CAPS policy in Firefox?

I am tired of sites blocking my CMD + c and CMD + v copy / paste. Especially when their javascript code allows CONTROL + c and CONTROL + v to go through without being captured.

I want to use the new CAPS security policy for Firefox 4 to create a rule that gives "noAccess" to any site trying to grab onkeypress from event handlers on any element and prevent them from reading e.which.

Here is a javascript code snippet that prevents me from inserting zipcode into the text area, because the site author wants "only numbers" in this field, so "CMD + v" (paste) is captured and dropped to the floor.

function numbersonly(myfield, e, dec) var key, keychar; if (e) key = e.which; else return true; keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true; else if ((("0123456789").indexOf(keychar) > -1)) return true; else return false; } 

Then the HTML code will have:

 <INPUT NAME="zipcode" onKeyPress="return numbersonly(this, event)"> 

How to install a policy in Firefox4 that disables the ability of sites to call this event handler function?

Using the "Control de Scripts" extension, I tried to add the following "block" to the "default" policy, which affects all sites, but no one worked to let me use a combination of Firefox metaphors, focusing on the text field that listens for this event handler:

HTMLInputElement.onKeyPress
Window.numbersonly
Window.onKeyPress
Window.onkeypress
event.preventDefault

Now we are working on Firefox 14, but not 4. Does this kind of noAccess support more accessible / suitable for Firefox users like me?

I am looking for an answer on how to prevent the capture of keystroke events using CAPS, rather than finding the name of each function on each website and disabling the functions one by one.

+7
source share
3 answers

Why not redefine the function so that it does nothing. Open mozilla's javascript console and just override the violation function.

 numbersonly = function (a,b,c) { return true; }; 
+3
source

If there is a function that annoys you, just open the javascript console and redefine the function.
To open it in firefow, press ctrl + shift + k

+2
source

Just adding a line to the policy file:

 // This line creates a new policy named "stopnums" user_pref("capability.policy.policynames", "stopnums"); // Add the offending site to the stopnums policy user_pref("capability.policy.stopnums.sites", "http://www.exemple.com"); // Set the stopnums policy to deny a site from accessing "numbersonly" user_pref("capability.policy.stopnums.numbersonly", "noAccess"); 

You can find an overview here: https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/A_brief_guide_to_Mozilla_preferences?redirectlocale=en-US&redirectslug=A_Brief_Guide_to_Mozilla_Preferences#modifying

And a full explanation here: http://www.mozilla.org/projects/security/components/ConfigPolicy.html

+1
source

All Articles