Reputation: 193
I am developing an html page that displays results for a given question.
I want people to be able to copy paste at their will, if they wish. Part of the text though is not useful. It's only comments about the results. I want to avoid that text from being copied. Only to facilitate work and not to hide or protect it.
I've seen other questions on SO like Prevent copying text in web-page But these focus more on either protecting full pages or large areas of text from being copied. I want to avoid only small portions within copiable html.
How can I achieve a clean copy paste from text in an html page avoiding unnecessary content?
Upvotes: 1
Views: 179
Reputation: 272909
You can use pseudo element in order to show content that we cannot copy/paste:
div::after {
content:attr(data-comments);
}
<div data-comments="comments that cannot copy paste">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ac nibh vitae ex posuere rhoncus. Fusce in egestas ex. Etiam tincidunt lacus sit amet lorem rutrum mollis ac pellentesque ligula.
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ac nibh vitae ex posuere rhoncus.
</div>
Upvotes: 1