How to implement prohibition of selection in html

藏色散人
Release: 2021-04-12 09:36:26
Original
2842 people have browsed it

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; }
Copy after login

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:


        
Copy after login

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;};
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!