Site content is prohibited to copy and paste save as js code

  • 2020-03-30 02:09:22
  • OfStack

  1. Disable right-click and copy
Method 1:
Add the following code to the page:

< Script language = "Javascript" >
Document. The oncontextmenu = new Function (" event. ReturnValue = false ");
Document. The onselectstart = new Function (" event. ReturnValue = false ");
< / script>

Method 2:

In < Body> Add the following code:

< Body oncontextmenu="return false" onselectstart="return false">
or
< Body oncontextmenu = "event. ReturnValue = false" onselectstart = "event. ReturnValue = false" >

Essentially, method 2 is the same as method 1.

Method 3:

If replication is limited, it can be done in < Body> Add the following code:
< Body oncopy="alert(' sorry, no copying! '); Return false;" >

2. Disable the menu "file "-" save as"
If you simply disable right-click and select copy, others can also copy the file by "file "-" save as" in the browser menu. In order to make the kao

Shell failure, available in < Body> With < / body> Add the following code between:

< Noscript>
< Iframe SRC = ". * HTM "> < / iframe>
< / noscript>

In this way, when the user saves the Web page, the "Web page cannot be saved" error will appear.

Alternatively, you can use the event.preventdefault () method to block oncontextmenu() and onselectstart()

Document. Oncontextmenu = function (evt) {
Evt. The preventDefault ();
}

Document. The onselectstart = function (evt) {
Evt. The preventDefault ();
};

Now that you can disable it, of course you can also enable it by reassign the event, either to null or to a string or a Boolean. Such as:

Document. The oncontextmenu = "";
Document. The onselectstart = true;

Or disable js: open Google browser, select "Settings" and select "privacy Settings". Select "content Settings" and select "JavaScript".


Related articles: