Selectable input fields and textareas but no other content selectable in Firefox? - html

I need to prevent users from selecting elements in my web app UI, except for text in input fields and textareas. For Firefox, the technique seems to be to use this css:
* { -moz-user-select: none; }
And that works well enough (tested Firefox 3.5.2), except that you cannot then select within input fields or textareas.
I tried dividing it into
div,td,span,img { -moz-user-select: none; }
input,textarea { -moz-user-select: text; }
however, if the input field is inside of a div, td, or span, it is not selectable. It seems that the -moz-user-select property is applied to all children as well, no matter if those children override the setting. Does anyone know a way around this aside from setting this at a far more granular (and annoying) level for specific elements?
NOTE this is not for security purposes. I am fine having users view source or advanced users turning this off. But for web UI's with drag-and-drop functionality, or just those that are supposed to behave like an application in general rather than like a document, it is really weird to be able to accidentally select text. And it happens often for most users.

* { -moz-user-select: -moz-none; }
input,textarea { -moz-user-select: text; }

You are fighting a lost cause. If I really want to select text from your page, or get it in some way, I will.
However, on to your question. Try adding !important to the end, so it looks like this:
div,td,span,img { -moz-user-select: none; }
input,textarea { -moz-user-select: text !important; }

Related

Input file not opening File Upload box on IE

I have a label element which, along with its corresponding input type="file", also contains an img sandwiched between two span elements.
The input itself is declared as display:none, allowing the label to do the job of launching the File Upload box when any element inside it is clicked. This, of course, works swimmingly in every major browser except IE. In IE, clicking anywhere inside the label other than the img will launch the File Upload box, but clicking the img will not...
You can see this issue replicated by opening this fiddle in IE alongside any other browser.
Strangely, the issue can be isolated down to the presence of the form. For some reason when the form wrapper is removed the label functions correctly. I obviously can't use this as a solution though. Thoughts?
It is a known bug in IE you can see it in Microsoft Connect
To solve simply add pointer-events: none; to the <img>
It can cause some browsers to highlight the image when being clicked. To avoid that make the image unselectable.
The full solution is:
.selector-for-image {
pointer-events: none;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
See updated JSFiddle

IE 11 - user-select override value not being applied on child elements

For a task, the product owner wants to disable most HTML elements from being highlighted via Ctrl-A. The way I'm doing this is to set
body {
-{$prefix}-user-select: none;
user-select: none;
}
div.element-to-select {
-{$prefix}-user-select: all;
user-select: all;
}
I've also made up a codepen at http://codepen.io/daredevil82/pen/zxPzbJ to demonstrate. In this example, when mouse focus is on the white area, a Ctrl-A press will have the Select text highlighted but the No Select text will remain un-highlighted in Firefox 35+ and Chrome, but both elements will not be selected in IE 11.
Is there a way around this behavior for IE?
The Working Draft User Interface for CSS3 defined user-select like this:
This property is not inherited, but it does affect children in the
same way that display: none does, it limits it. That is if an element
is user-select: none, it doesn't matter what the user-select value
is of its children, the element's contents or it's childrens contents
cannot be selected.
Firefox implemented -moz-user-select: none according to that draft; and also implemented -moz-user-select: -moz-none, which allowed selection to be re-enabled on sub-elements using -moz-user-select: text.
However, starting with Firefox 21, -moz-user-select: none behaves like -moz-user-select: -moz-none, due to Bug 816298:
Our -moz-user-select: none behaves as proposed in the css3-userint TR
but WebKit, IE, and Opera's -XXX-user-select: none behave like
-moz-user-select: -moz-none.
Not sure if the bug is wrong and IE also followed the proposed spec, or if IE changed the behavior later. But now IE seems to be the only major browser which follows it.
However, you can't rely on that draft. The User interface for CSS3 module has been superseded by CSS Basic User Interface Module Level 3 (CSS3 UI), which doesn't include user-select.
Therefore, since user-select is no longer standard, implementators won't probably change their implementations in order to have a common behavior among different browsers.

HTML5 contenteditable attribute not working properly on iOS7 Mobile Safari

It seems that the contenteditable attribute (which worked fine on iOS6) has stopped working on iOS7 webkit. Though the browser seems to recognize the field as editable, and brings up the keyboard, any input seems to close it, or it fails to register. Any encounter the same problem, or have any workarounds?
You can try it out over here - http://html5demos.com/contenteditable
Thanks!
I ran into this problem today. The solution for me was to set user-select to "text" in the CSS for any editable elements:
* {
-webkit-user-select: none;
user-select: none;
}
input,
textarea,
[contenteditable] {
-webkit-user-select: text;
user-select: text;
}
I was having the same issue and the below link helped me resolve it.
https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-SW1
The solution that worked for me was to set "-webkit-user-modify" property to "read-write" for any editable element (you have defined as contenteditable)
*{
-webkit-user-modify:read-write;
}

Unselectable text in HTML on iOS

If you visit this page on iOS, you will not be able to select any text. This page doesn't contain any javascript or selection blocking code, actually if you open it on desktop browser everything will work.
I'm trying to implement EPUB3 reader on iOS and this page was generated with WYSIWYG EPUB3 editor.
So the problem is: How can I enable selection on this page without changing it visual layout?
And really important thing is: I'm hoping for solution which can be automated. So that I can preprocess this html files before opening in my reader.
Update: Selection starts working only when zoomed to about 400%.
Here is a cross-browser list of styles for non-selectable text:
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: moz-none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
You can also set them to select text as well:
-webkit-touch-callout: default;
-webkit-user-select: text;
-khtml-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
-o-user-select: text;
user-select: text;
The -webkit-touch-callout property allows you to dictate what does or doesn’t happen when a user taps and holds on a link on iOS. The default value is default and tap-holding on a link brings up the link bubble dialog; by using the value of none, that bubble never comes up.
The -khtml prefix predates the -webkit prefix and provides support for Safari 2.0-
The -moz prefix is defined twice with the value none and the value -moz-none on purpose. Using -moz-none rather than none prevents elements and sub-elements from being selectable. However some older browsers like Netscape won’t recognize moz-none so it’s still necessary to define none for them.
The -o prefix isn't supported but I have come across recommendations to include it for future proofing and it doesn't hurt unless minification is critical.
Non-prefixed property should be last in line.
The computed height of #div8 is 0. Changing this to 100% fixes the issue for me.
drop
<meta charset="UTF-8" />
into the head
Do u try this please :
body {
zoom: 1;
margin: 0;
padding: 0;
width: 512px;
height: 768px;
-webkit-user-select: text; // THIS ALLOW SELECT TEXT ON IOS
}
-webkit-user-select, which are also value : "none", "all", "element"

why the attribute contentEditable of input text box does not work in Chrome?

In my .net project ,these are so many codes like this
< asp:TextBox ID="txtDeparment" runat="server" contentEditable="false">< /asp:TextBox>
it works well In IE,but in Chrome, it doesn't work. but you cann't simply replace it by ReadOnly.
How can I resolve this problem in minimum changes?
In order to make a text box un-editable you should use the following CSS attributes:
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
These CSS attributes don't allow selecting the element, which in the case of an input field, also denies editing it.