We want to automatically add article links to the copy when copying content. There are many methods to implement js, jquery, and flash. Below I will introduce wordpress as an example.
Method
You can add a function to your WordPress site: After the content is copied, the link of the post is automatically added when it is pasted.
Add the following code to the topic's functions. php file:
The Code is as follows: |
Copy code |
Function add_copyright_text (){ If (is_single () {?> <Script type = 'text/javascript '> Function addLink (){ If ( Window. getSelection (). containsNode ( Document. getElementsByClassName ('entry-content') [0], true )){ Var body_element = document. getElementsByTagName ('body') [0]; Var selection; Selection = window. getSelection (); Var oldselection = selection Var pagelink = "<br/> Read more: <? Php the_title ();?> <A href = '<? Php echo get_permalink (get_the_ID ();?> '> <? Php echo get_permalink (get_the_ID ();?> </A> "; // modify this line of code as required. 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. oncopy = addLink; </Script> <? Php } } Add_action ('wp _ head', 'add _ copyright_text '); |
If you do not want to modify the PHP file, we can directly implement it using js without adding the above Code.
The Code is as follows: |
Copy code |
<Script type = "text/javascript"> Document. body. oncopy = function (){ Settimeout (function () { Var text = clipboarddata. getdata ("text "); If (text ){ Text = text + "rn this article comes from [Left Bank] (http://www.bKjia. c0m) Original Source:" + location. href; Clipboarddata. setdata ("text", text ); } }, 100) } </Script>
|
For more details, see: http://www.bKjia. c0m/wy/js-ajax/41045.htm