Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

WordPress article how to realize the method of preventing copy code

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you the WordPress article on how to achieve anti-copy code, I hope you will learn a lot after reading this article, let's discuss it together!

Method 1:

Open the current topic header template header.php to find: add the following code to the end:

/ / disable right-click _ document.oncontextmenu = function () {return false}; / / prohibit drag and drop of pictures _ document.ondragstart = function () {return false}; / / disable selection of text _ document.onselectstart = function () {if (event.srcElement.type! = "text" & & event.srcElement.type! = "textarea" & & event.srcElement.type! = "password") return false;else return true;} If (window.sidebar) {_ document.onmousedown = function (e) {var obj = e.target if (obj.tagName.toUpperCase ()) = = "INPUT" | | obj.tagName.toUpperCase () = = "TEXTAREA" | | obj.tagName.toUpperCase () = = "PASSWORD") return true;else return false;}}; / / prohibit frame tags from referencing if (parent.frames.length > 0) top.location.replace_ (document.location)

Method 2:

The above method is a bit messy when viewing the source code. You can create a new file named copyright.js in the current theme directory and add the following code:

/ / disable right-click _ document.oncontextmenu = function () {return false}; / / prohibit drag and drop of pictures _ document.ondragstart = function () {return false}; / / disable selection of text _ document.onselectstart = function () {if (event.srcElement.type! = "text" & & event.srcElement.type! = "textarea" & & event.srcElement.type! = "password") return false;else return true;} If (window.sidebar) {_ document.onmousedown = function (e) {var obj = e.target if (obj.tagName.toUpperCase ()) = = "INPUT" | | obj.tagName.toUpperCase () = = "TEXTAREA" | | obj.tagName.toUpperCase () = = "PASSWORD") return true;else return false;}}; / / prohibit frame tags from referencing if (parent.frames.length > 0) top.location.replace_ (document.location)

Then add the following code to the end of the current theme function template functions.php:

Function copyrightpro_scripts () {wp_enqueue_script ('copyright', get_template_directory_uri (). '/ copyright.js', array (), false);} if (! Current_user_can ('level_10')) {add_action (' wp_enqueue_scripts', 'copyrightpro_scripts');}

A judgment is added to the code, and the administrator logs in for a while, and the anti-copy code is invalid.

Of course, the above method is only a hoax, after the browser disables JavaScript, it will lose its effect.

After reading this article, I believe you have a certain understanding of the WordPress article on how to achieve copy-proof code, want to know more about it, welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 286

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report