4

Some form validators block CTRL+C/CTRL+V on some input fields. Is there a quick bookmarklet or something that could allow me to use my keyboard properly. Or, perhaps, browsers allow my to override that kind of rude behavior of some pages?

EDIT: What I'm looking for is similar solution like the one that can be used to enable right-click on a page by executing a javascript snippet withing context of the page:

javascript:void(document.oncontextmenu=null) 

So far, I think that there is no similar solution with javascript snippet without involvment with 3rd party tools like Greasemonkey

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Pavel P
  • 15,789
  • 11
  • 79
  • 128
  • 6
  • 2
    consider that sometimes this is a good idea. e.g. a password verification field. if you typoed the initial password, copy-pastaing the bad password is just going to be a pain for everyone very shortly. – Marc B Nov 04 '12 at 05:13
  • 2
    Password fields (if this is what you're talking about) are not copyable, at least under Windows. This is a security measurement. – Alvin Wong Nov 04 '12 at 05:19
  • 4
    *Greasemonkey* is what you need - https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/ – techfoobar Nov 04 '12 at 05:22
  • @casperOne It might sound to be off topic. Most likely this question doesn't have solution similar to javascript right-click trick. – Pavel P Nov 08 '12 at 21:18

2 Answers2

2

That depends on how it is done. Also, removing/disabling event listeners is always risky, you might harm the functionality of the site seriously - and you never know whether a handler does evil or good things, least you can know whether there is a handler at all.

So, I've skimmed the first few Google results for "javascript prevent copy paste" and found mostly foolish scripts: Disable pasting text into HTML form, Prevent Copy, Cut and Paste into HTML Input Text Fields, not working example. So what a script could do now:

  • remove all on-copy, -paste, -input, -cut, -drag, etc properties of input elements
  • capture these event types on the document and stop their propagation, so (bubble) handlers will never get called and can't prevent the default action

Yet, as already said, this can't hinder everything. The input event, a very useful one, is cleverly used by this solution to prevent inserting more than one character at once. So you would need to decide whether you want to stop that event and possible break the application.

var evts = ["copy", "paste", "cut", "drag", "selectionstart?", "input?", …?];
var els = [document, document.body].concat(
  [].slice.call(document.getElementsByTagName("input")),
  [].slice.call(document.getElementsByTagName("textarea"))
);
function trap(e) { e.stopPropagation(); }
for (var i=0; i<evts.length; i++) {
    var evt = "on"+evts[i].charAt(0).toUpperCase()+evts[i].substr(1);
    for (var j=0; j<els.length; j++)
        els[j][evt] = null; // remove handler
    document.addEventListener(evts[i], trap, true); // capture phase
}
Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
1

Another solution on windows: AutoHotkey.

SendRaw, %Clipboard%

For example, the following binds to ctrl+F3 to type out the clipboard contents. Just put this in a file called typeclipboard.ahk and run it with AutoHotkey:

^F3::SendRaw, %Clipboard%
Johann
  • 4,107
  • 3
  • 40
  • 39