Home  >  Article  >  Web Front-end  >  How to set text in html so that it cannot be selected

How to set text in html so that it cannot be selected

藏色散人
藏色散人Original
2021-11-10 14:24:326874browse

htmlHow to set text that cannot be selected: 1. Create an HTML page file; 2. Set the css style to "user-seletct: none;-webkit-user-seletct: none;-moz-user-seletct : none;" will do.

How to set text in html so that it cannot be selected

The operating environment of this article: windows7 system, HTML5 version, DELL G3 computer

html How to set text so that it cannot be selected?

Methods to control the content of HTML pages that cannot be selected

There are two methods

One: css method

user-seletct: none;
-webkit-user-seletct: none;
-moz-user-seletct: none;
-ms-user-seletct: none;

none: The content cannot be selected

text: Content can be selected

2: js method

document.body.onselectstart = function(){
  return false;
}

returns false, cannot be selected

returns true, can be selected

Recommended learning : "HTML5 video tutorial"

The above is the detailed content of How to set text in html so that it cannot be selected. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn