How can web pages prevent the insertion of events?

In a study of my question about superuser How can I selectively disable paste blockers I found that on a particular site that I encountered did not use any of the methods, any of the existing solutions are expected.

While global solutions for using preferences dom.event.clipboardevents.enabled or disable clipboard manipulation in FireFox, they also suffer from the problem, there are legitimate reasons why websites may want to connect to onpaste (for example, text support google docs or facebook link processing), so I don’t want this feature to be completely disabled.

The solutions we found (e.g. Derek Prior Re-enable passwords on annoying web forms and improved Re-enable passwords on annoying web forms (v2) by Chris Bailey) that use bookmarklets to selectively disable functionality insert a blocking code , it seems do not work with on this page .

This makes me wonder how the petplanet site disables insertion, why existing solutions do not work with this site, and what are other ways to prevent insertion blocking? The answer to these questions should help us write a comprehensive bookmarklet solution so that this harmful practice can work well.

+5
source share
2 answers

You can execute the jQuery paste event to listen for the event and use prevenrDefault() to prevent the event.

In this page they used jQuery below

 $('#pwd, #pwd2').bind('paste',function(e){ e.preventDefault(); alert('Please type your password.') }); 

Open Firebug, go to the Scripts tab, then find the line Please type your password. (Firebug search bar, not the browser search bar.), you will find the code above. And the code is present logon.asp

Picture
To disable , you simply use the off method, like this $('#id1').off() . this discards all events for an element with id='id1'

+2
source

As far as I know, you can only "disable" such things using JavaScript.

As I can imagine, this is not really the answer you are looking for, you can do something like this:

 var keys = []; window.addEventListener("keydown", function(e){ keys[e.keyCode] = true; checkCombinations(e); }, false); window.addEventListener('keyup', function(e){ keys[e.keyCode] = false; }, false); function checkCombinations(e){ // try and prevent cntrl+v (paste) if(keys["v".charCodeAt(0)] && e.ctrlKey){ alert("You're not allowed to paste"); e.preventDefault(); } } 

Source: Get a list of all keys currently pressed in Javascript

0
source

Source: https://habr.com/ru/post/1210098/


All Articles