Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a web pages prevent paste events?

In researching my Super User question How can I selectively disable paste blockers I discovered that the specific site I had a problem with did not appear to use any of the methods any of the existing solutions expected.

While the global solutions of using the dom.event.clipboardevents.enabled preference or Disable clipboard manipulations plugin in FireFox worked, they also also suffer the problem that there are legitimate reasons why websites might want to hook into onpaste (such as google docs rich text support or facebooks link handling) so I don't want that functionality completely disabled.

The solutions we have found (such as Derek Prior's Re-enabling Password Pasting on Annoying Web Forms and the improved Re-enabling Password Pasting on Annoying Web Forms (v2) by Chris Bailey) which use bookmarklets to selectively disable the functionality of paste blocking code don't appear to work with this page.

This makes me wonder, how does the petplanet website disable paste, why don't the existing solutions work with this site, and what other ways are there to prevent paste blocking? Answering these questions should help us write a comprehensive bookmarklet solution, so this pernicious practice can be worked around for good.

like image 832
Mark Booth Avatar asked Dec 30 '14 11:12

Mark Booth


People also ask

How do you prevent input fields from pasting?

The onpaste attribute lets us prevent pasting into the form. Adding the autocomplete attribute as well as preventing drag and drop into the element. If you want to avoid the on{event} code in the HTML, you can do it the cleaner way: myElement.

How do I disable paste in HTML?

You can disable cut, copy, and paste using the oncut, oncopy, and onpaste event attributes with the target HTML elements. If you want to disable cut, copy, and paste for the complete web page, you need to use these event attributes with the body tag.


1 Answers

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

In this page , they used the below jQuery

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

Open Firebug, Go to Scripts Tab, then search the string Please type your password. (Firebug Search Bar , not browser search bar.) , you'll find above code. And Code is present logon.asp

Image
To Disable it , you simply use off method like this $('#id1').off(). this unbinds all events for the element that has id='id1'

like image 70
J Santosh Avatar answered Sep 28 '22 22:09

J Santosh