I just discovered the user-select
attribute of CSS. I was wanting to find a way for people to copy the displayed results on a page, without copying the headings as well (and a few other things).
Each browser is a bit different when they attempt to select something. But I've been testing mainly in Chrome. Fiddle Code
HTML
<div>
<span class="no-select heading">Heading 1 - can't select it</span>
<p>This text you can select & copy.</p>
<span class="no-select heading">Heading 2 - can't select it</span>
<p>This text you can select & copy.</p>
</div>
CSS
.no-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
The results:
To me, it looks like they would only be able to copy the highlighted text. However, when copying what is highlighted - it does have heading 2
, but it did not copy heading 1
. Why is this?
This text you can select & copy.
Heading 2 - can't select it
This text you can select & copy.
Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.
Android can cut, copy and paste text, and like a computer, the operating system transfers the data to the clipboard. Unless you use an app or extension like Clipper or aNdClip to retain your clipboard history, however, once you copy new data to the clipboard, the old information is lost.
You can disable cut, copy, and paste on a web page using the jQuery bind() function. In the bind() function, you have to specify the cut, copy, and paste events that are fired when a user tries to cut, copy, or paste anything on the web page.
In Excel 2007 this can be displayed by displaying the Home tab and clicking on the small icon in the bottom right corner of the Clipboard group. This clipboard can hold a maximum of 24 items (text and graphics) and is also commonly referred to as the Clipboard viewer.
I don't really think its all that surprising, the user-select
property is to prevent a user from selecting an elements' content. Nowhere in the Basic UI Module does it mention the behaviour regarding copying content. I would imagine this is why there are variations among different browsers.
MDN also states:
Controls the appearance (only) of selection. This does not have any affect on actual selection operation.
The comments in this WebKit Bugzilla report also say the same thing.
I had the same problem and found the following solution. https://danoc.me/blog/css-prevent-copy/
html:
<p data-pseudo-content="Lorem Ipsum"></p>
css:
[data-pseudo-content]::before {
content: attr(data-pseudo-content);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With