1

I hava a list for name, it can click to show detail of each.But I don't want names of that list be select and copy.It just a protect.How to do?

can put a transparent layer on it, or use onselectstart event,but not good

MarioDu
  • 135
  • 2
  • 8

6 Answers6

1

With this CSS

.unselectable {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}

And this HTML

<body>
  <p class="unselectable">The user is not able to select this text in Firefox, Chrome, Safari and IE.</p>

</body>

The paragraph can't be selected.

It's nice for buttons and things where the text is not useful to copy and paste.

This can't be considered security, as the user can obviously disable the CSS or just view source. (Or use wget/curl/raw sockets to get the content).

Browser support is pretty good: http://caniuse.com/user-select-none

IE10 and up (though of course IE10 is now the most popular version of IE), + all other browsers.

If for some reason you are supporting older versions of IE with such a trivial feature, you can add unselectable="on" on the element.

Rich Bradshaw
  • 71,795
  • 44
  • 182
  • 241
1

If it's just for esthetic because you need some action in Javascript which make weird thing with the selection, you can disabled the user selection by this CSS property:

.block {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}

However, the user will always be able to select the content by an other manner: source code, by deactivate the CSS, save the page on his disk, etc. You can't protect your data from being copy on the Internet. If you want to keep it for you only, don't share it on the Web :) See also this post which explains the subject for another problem.

Community
  • 1
  • 1
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
0

When you want to protect information, don't put it on the internet - simple as that.

That being said, one way to make text less machine-readable would be to turn it into an image. But it would still be possible to extract the text using optical character recognition. Obfuscating the text like in a captcha could make this harder, but 1. still not impossible (breaking captchas is a well-researched field) and 2. make the user-experience worse, especially for vision-impaired people.

Philipp
  • 67,764
  • 9
  • 118
  • 153
0

Well you can disable right click on page using JavaScript but it won't prevent user from copying content from your website.

There are still other options to copy content:

  • Print Screen OR any other snipping tool
  • Save page
  • Print Screen and extract text using Microsoft One Note.
  • View page source and copy

If you put something on Internet, there are chances of getting it copied. You can prevent normal users from copying using JavaScript and other measurements but advanced user will copy it any way.

Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43
0

you can try to render all texts as images, no one can stop them using print screen but at least there will be no copying. see imagettftext (http://php.net/manual/en/function.imagettftext.php) or http://sgss.co/previous/experiments/phpfontimagegenerator2/

or just google some more methods of rendering text as image.

Victor Radu
  • 2,262
  • 1
  • 12
  • 18
-1

You can't. Don't try.

If the user can see it, they can copy it (somehow).

David-SkyMesh
  • 5,041
  • 1
  • 31
  • 38