-1

Is there any way to disallow copying to the clipboard the contents of the spans within the div? When the user highlights all of the div text with their mouse, I don't want the span contents (the numbers in the example below) copying to the clipboard as well.

<div class="codebox">
<span>1</span>Some text here<br />
<span>2</span>More text here
</div>

Im hoping this is possible with just CSS, but perhaps jQuery?

MultiDev
  • 10,389
  • 24
  • 81
  • 148
  • if you are trying to do this to protect content it is futile and a waste of time, if it's in the browser anyone can get it – charlietfl Jul 28 '14 at 02:47
  • You can do [**this**](http://jsfiddle.net/zSV2h/) using CSS3. This won't be fool proof as charlietfl has mentioned above, but if you really want it then you can try something like this. No JS/jQuery needed for this. *Edit:* This also is having problems with multi-lines. – Harry Jul 28 '14 at 02:50
  • Im not doing it to try to protect it, I just dont want it copied to the clipboard along with the other text. – MultiDev Jul 28 '14 at 02:50
  • Having said what I did in my earlier comment, judging by your contents I think what you really need is the good old `ol` tag. I don't think the numbering in it gets copied. [Demo](http://jsfiddle.net/zSV2h/2/) – Harry Jul 28 '14 at 02:52
  • @Harry I tried the fiddle you posted but it also copied the line numbers – MultiDev Jul 28 '14 at 02:57
  • @JohnRobinson: The first or the second? The first has issues when you do a Ctrl + A kind of stuff or drag your mouse from top to bottom. – Harry Jul 28 '14 at 02:58
  • Look, your question is exactly the same as the one I linked. Nothing has changed. It's impossible to prevent – Zach Saucier Jul 28 '14 at 03:29

1 Answers1

0

This css will prevent selection via the mouse:

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

But anyone can still copy the text easily via the source...

Robbie
  • 46
  • 1
  • 5
  • Im not trying to protect the content for security issues, Im trying to disable copying to the clipboard for convenience reasons. Im not worried about security here. And the CSS you posted above only prevents highlighting with the mouse- the contents are still copied to the clipboard. – MultiDev Jul 28 '14 at 03:26
  • @JohnRobinson: What type of content does your span have? Is it always a number? I mean, what is the purpose of that span. Maybe there are better alternatives. – Harry Jul 28 '14 at 03:34