Copy web content paste automatically after the implementation of the url of the script house of special arrangement

  • 2020-03-30 04:09:55
  • OfStack

Unexpectedly inadvertently a function, now has been spread so fiercely by everyone, think at the outset after we released, the second day found that a lot of sites have added this function, a little regret, or our chain will be more. Of course, there are also antipathy, tools are good to see the use of the people.

Open some websites, when we browse some articles, feel good, therefore, often copy the articles of these websites;

After, paste into Word or notepad inside, save, in the implementation of "take doctrine" at the same time, it will be "own"!
If you are a webmaster like a small bee, every day diligent, every day like an old cow, so, when your website content is owned by others without any reason did not indicate the article source address, I think, you will fire up!
Therefore, to avoid the occurrence of this kind of situation, a lot of stationmaster do so!
Add such a function to the web page, when others copy the site content, paste into Word or notepad and other software, will automatically add the site address or the detailed address of the article source!
If you also encounter such a situation, please follow me to learn together, how to achieve such an effect!

Implementation method:

The method is very simple, using the following code can be!


<script type="text/javascript">
document.body.oncopy = function () {
 setTimeout( function () {
  var text = clipboardData.getData("text");
  if (text) {
   text = text + "rn This article from the : Web site name (//www.jb51.net)   "+location.href; ClipboardData. SetData (" text ", the text). < br / >   }
    }, 100 )
}
</script>

Copy and paste the above code into the corresponding page of your website.

Note: this code is typically placed in < Body> In the area, or choose to put somewhere!

Knowledge expansion:

Although the above code can prevent the copy of automatically add url, but, the flexibility is not big, later to modify or make any changes, have to modify this code is not, then, we can use the method of introducing JS file in the page to achieve flexible function!

Open notepad and copy and paste the following contents in it (this code is similar to the above code, but not the same, please note) :


document.body.oncopy = function () {
 setTimeout( function () {
  var text = clipboardData.getData("text");
  if (text) {
   text = text + "rn This article from the : The home of the script (//www.jb51.net) article address: "+location.href; ClipboardData. SetData (" text ", the text). < br / >   }
    }, 100 )
}

After that, save it as XX. Js such a file, save the site in the corresponding directory!

Finally, you can simply introduce the xx.js file above into the page, as follows:

< Script SRC = "DataFiles/Java/AddMyUrl js" type = "text/jscript" > < / script>

The above red color code, is the example code!

Note that the introduced code is generally placed at the end of the article, in < / body> Before!

The above code is to get the content of the clipboard through js, while the following code is to get the selected content through js, the function is the same. But not many use this.







 Copy the content of the article and automatically add your url information 







 This text is a test. You can copy it and paste it somewhere else to see if it contains the website address. 



[Ctrl+A]

The above copy of the web content, paste automatically after the introduction of the url is first here, later found better for you to provide.


Related articles: