Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable user select in a readOnly html element on iPad safari?

I have an HTML element in my web page on iPad and it must be read only to prevent users updating the content,using readOnly='readOnly' makes the element unselectable and text content of the element can not be copied at all.

is there any way to make the element read only and the user can select/copy the text content????

like image 706
aomar Avatar asked Oct 07 '12 06:10

aomar


People also ask

How do you make a selection readonly in HTML?

According to HTML specs, the select tag in HTML doesn't have a readonly attribute, only a disabled attribute. So if you want to keep the user from changing the dropdown, you have to use disabled .

How do I make an input element read only?

The readonly attribute of <input> element in HTML is used to specify that the input field is read-only. If an input is readonly, then it's content cannot be changed but can be copied and highlighted. It is a boolean attribute. Example: This example uses HTML <input> readonly Attribute.

What is difference between readonly and disabled?

A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit. Another difference is that readonly elements can be focused (and getting focused when "tabbing" through a form) while disabled elements can't.

How do you make text fields non editable in HTML?

The readonly attribute makes a form control non-editable (or “read only”). A read-only field can't be modified, but, unlike disabled , you can tab into it, highlight it, and copy its contents. Setting the value to null does not remove the effects of the attribute. Instead use removeAttribute('readonly') .


1 Answers

just i removed the readOnly attribute and added the following onkeydown and oncut events to simulate readOnly behavior

<input type="textarea" 
    onkeydown="event.preventDefault();event.stopPropagation();return false;" 
    oncut="event.preventDefault();event.stopPropagation();return false;">
like image 68
aomar Avatar answered Oct 20 '22 01:10

aomar