Abstract: In our project, usually in order to ensure data security and protect user personal information, individual pages need to disable the right click, copy, paste and input box automatic filling function. So in this supplement and summary of our development of a few common operations.

This article is shared by Bai Lu First Shuai in Huawei cloud community principle and Operation Description of Disabling right-click and Copy-paste (Cut) Functions using JS on Form Pages.

preface

In our projects, in order to ensure data security and protect users’ personal information, the functions of right clicking, copy and paste and automatic filling of input boxes need to be disabled on individual pages. So in this supplement and summary of our development of a few common operations.

First, disable the right mouse button

1.1 analysis and explanation

Disable copy and paste and other illegal operations by disabling the right click TAB.

1.2. Operation principle

We use the button event property in JS to disable the right mouse button. Pop up a prompt box instead of a right-click TAB.

1.3. Realization effect

1.4. Implementation code

Import the following JS code to the page where you want to disable right-click

1.5. Supplement: Button event attribute in JS

The button event property returns an integer indicating which mouse button was clicked when the event was triggered.

The syntax is as follows:

2. Disable copy and paste

2.1 analysis and description

Disable the user from copying and pasting (cutting and cutting) on the current page by disabling the shortcut keys Ctrl+C/V/X.

2.2. Implementation code

Disable copy and paste for the entire page. Add the following code to the page body tag:

Parameter Description:

3. Disable the automatic filling function of input boxes

3.1 Analysis and explanation

If we do not set the input field, the previous record entered by the user will be automatically filled in the next time. Surely you don’t want your records on some small website to be automatically filled in by another student’s login username and let them find out your little secret?

In that case, we can disable the automatic filling of the input box so that the records entered by the previous user will not be automatically filled when another user enters, thus protecting the privacy of the user’s personal information.

3.2. Achieve the effect

3.3. Implementation code

conclusion

Native JS is fascinating and should never be abandoned in pursuit of a ready-made framework. In order to protect user privacy and information security in the development, we need to be rigorous in all aspects, in order to give users the best experience, whether front-end or back-end, to fully do the details, the premise of anything is to do a qualified programmer. Technology drives services, and services generate revenue and revenue.

Click to follow, the first time to learn about Huawei cloud fresh technology ~