Home>Article>Web Front-end> How to implement prohibition of selection in html

How to implement prohibition of selection in html

藏色散人
藏色散人 Original
2021-04-12 09:36:26 2852browse

How to implement prohibition of html selection: 1. Prohibit html content from being selected through css; 2. Prohibit html content from being selected by adding onselectstart and other attributes to the body tag; 3. Through js Add onselectstart statement to implement prohibition.

How to implement prohibition of selection in html

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

In the page, html content is prohibited from being selected

1. Through css

*{ moz-user-select: -moz-none; -moz-user-select: none; -o-user-select:none; -khtml-user-select:none; -webkit-user-select:none; -ms-user-select:none; user-select:none; }

user-select attribute: refer to https://www.html.cn/book /css/properties/user-interface/user-select.htm

2. By adding the following attributes to the body tag:


      

The first sentence prohibits right-clicking, and the latter sentence prohibits copying. of.

3. Add the following two lines of statements in js:

//禁止页面选择以及鼠标右键 document.function(){return false;}; document.onselectstart=function(){return false;};

[Recommended learning:HTML video tutorial]

The above is the detailed content of How to implement prohibition of selection in html. 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