Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow Copy/Paste in a disabled input text box in Firefox browsers

Tags:

javascript

I have a input text box disabled:

   <input type="text" name="name" disabled="disabled" /> 

In IE and in Chrome you can copy and paste the value populated in that input field but in Firefox you cannot.

Firefox does not allow clipboard manipulation through JavaScript for valid security concerns.

Any suggestion? Is there a work around this?

like image 781
SergioKastro Avatar asked Jan 16 '12 07:01

SergioKastro


People also ask

How do you paste when paste is disabled?

Enable copy paste on websites that have disabled copy paste. How to use: - Click on the extension icon - After a popup is opened, use the “Enable copy paste for all websites” checkbox. - Manually refresh the page and see if the extension has successfully enabled copy paste functionality on the website.

How do I disable copy paste in TextBox?

Disable Copy and Paste in an ASP.NET Webpage TextBox without JavaScript; we need to set the following properties of the TextBox: oncopy="return false" onpaste="return false" oncut="return false"

How do I disable paste in HTML?

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 can we avoid copy paste in TextBox using jQuery?

Projects In JavaScript & JQuery To disable cut, copy and paste of a content in jQuery, use the jQuery bind() function.


2 Answers

readonly="readonly" will do the job

it should be supported by the major browsers

like image 98
Teneff Avatar answered Sep 18 '22 07:09

Teneff


I don't like using readonly="readonly", ever. It leaves the field focusable and reachable via tab keypress and, if, god forbid, the user hits the backspace key while the read-only field is focused, then most browsers treat it like the user hit the 'back' button and bring up the previously viewed page. Not what you want to see happen when you're filling out a large form, especially if you are using some archaic browser that doesn't preserve the form data when you hit the 'next' button to return to it. Also very, very bad when using some single-page web application, where 'back' takes you to a whole other world, and 'next' doesn't even restore your form, much less its data.

I've worked around this by rendering DIVs instead of input fields when I need the field disabled (or PRE instead of a textarea). Not always easy to do dynamically but I've managed to make fairly short work of it with AngularJS templates.

If you have time, head over to the Mozilla Bugzilla and ask them to fix it.

like image 27
Derek Avatar answered Sep 20 '22 07:09

Derek