As the saying goes, “The World Website is generally copied.” Online blog posts are often reproduced numerous times. Although blogging has no income, I want to write articles that should also be copyrighted.Even though blog posts often include copyright information under the “reproduced request source” below, for example, my is “unless specifically noted, all articles on this site are original blogs of Wang Baiyuan. In order to respect the author’s labor, reprint please specify Source http://wangbaiyuan.cn”; however, some adages are “too lazy to cramp” and copy and paste without copyright notice. The following code is designed for people who are too lazy to cramps. It is the function of automatically adding copyright information to the copy content when using JavaScript to realize the copy of the article. If so, there are people who intentionally delete the copyright information, and I will be silent.
JavaScript to achieve article copy plus copyright information
1. Background theme options add custom code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<script type='text/javascript'> Function addLink() { Var body_element = document.getElementsByTagName('body')[0]; Var selection; If(window.getSelection){//DOM,FF,Webkit,Chrome,IE10 Selection = window.getSelection(); Alert("The text was copied successfully!If there is a text incomplete, please use the right key to copy n Reprint Please indicate the source: "+document.location.href); }else if(document.getSelection){//IE10 Selection= document.getSelection(); Alert("The text was copied successfully!If there is a text incomplete, please use the right key to copy n Reprint Please indicate the source: "+document.location.href); }else if(document.selection){//IE6+10- Selection= document.selection.createRange().text; Alert("The text was copied successfully!If there is a text incomplete, please use the right key to copy n Reprint Please indicate the source: "+document.location.href); }else{ Selection= ""; Alert("Browser compatibility issues caused copying to fail!"); } Var pagelink = "<br /><br /> Reprinted please indicate the source: <a href='"+document.location.href+"'>"+document.location.href+"</a>"; Var copy_text = selection + pagelink; Var new_div = document.createElement('div'); New_div.style.left='-99999px'; New_div.style.position='absolute'; body_element.appendChild(new_div ); new_div.innerHTML = copy_text ; selection.selectAllChildren(new_div ); window.setTimeout(function() { body_element.removeChild(new_div ); },0); } Document.body.oncopy = addLink; </script> |
You can add this code to the end of the web page. If your theme doesn't have custom code, you can refer to the following method:
2.js script function in 2.functions.php
Place the following code in the template function file (before the last "?>"): By default, the code is loaded in the footer.
1 2 3 4 5 6 7 8 9 |
Function add_copyright_text() { ?> // Copy and paste method 1 js code here <;?php } Add_action( 'wp_footer', 'add_copyright_text'); |
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/javascript-implementation-article-copy-plus-copyright-information-2.html
No Comment