Home > Web Front-end > JS Tutorial > How to copy web page content and automatically add the URL after pasting (specially compiled by Script House)_javascript skills

How to copy web page content and automatically add the URL after pasting (specially compiled by Script House)_javascript skills

WBOY
Release: 2016-05-16 16:33:47
Original
1552 people have browsed it

I didn’t expect that Wuxin’s function has been spread so fiercely by everyone. I think after we released it, we found that many websites had added this function the next day. I regretted it a bit, otherwise we would have used external links. There will be more. Of course, there are also those who dislike it. Whether a tool is good depends on the person who uses it.

Today’s search found that there are still many friends who like this function. Here, the editor of Script House will continue to provide you with a specially compiled version. You can choose to use it according to your needs.

When we open some websites and browse certain articles, we feel very good, so we often copy the articles from these websites;

After that, paste it into Word or Notepad, save it, and "take it as your own" while implementing the "use principle"!
If you are a webmaster like a little bee who works hard every day and works like an old cow every day, then when the content of your website is occupied by others for no reason without indicating the source address of the article, I think you must It will become popular!
Therefore, in order to avoid this situation from happening, many webmasters do this!
Add such a function to the web page. When someone copies the website content and pastes it into software such as Word or Notepad, the website address or the detailed address of the article source will be automatically added!
If you also encounter such a situation, please learn with me how to achieve such an effect!

Implementation method:

The method is very simple, just use the following code!

Copy code The code is as follows:


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

Note: This code is usually placed in the area, or it can be placed somewhere selectively!

Knowledge expansion:

Although the above code can prevent the URL from being automatically added after copying, it is not very flexible. If you want to modify or make any changes in the future, you have to modify such code. Then, we can use the JS file to be introduced into the page. method to achieve flexible functionality!

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

Copy code The code is as follows:

document.body.oncopy = function () {
setTimeout( function () {
var text = clipboardData.getData("text");
if (text) {
text = text "rnArticle from: Script House (http://www.jb51.net) Article address:" location.href; clipboardData.setData("text", text);
}
}, 100 )
}

After that, save it as a file like XX.js and save it in the corresponding directory of the website!

Finally, just introduce the above XX.js file into the page. The following is the sample code quoted:

The above code in red color is the sample code quoted!

Note: The introduced code is usually placed after the article content and before !

Our above code all obtains the contents of the clipboard through js, while the following one obtains the selected content through js. The function is the same. But not many people use this.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template