当前位置:网站首页>Method of copying web page content and automatically adding copyright information (compatible with ie, Firefox and chrome)
Method of copying web page content and automatically adding copyright information (compatible with ie, Firefox and chrome)
2022-06-23 17:48:00 【It workers】
The method of automatically adding copyright information to the contents of the copying network
You can find many similar codes on the Internet , Join the web body Part of it .
For example, the following code :
// Copy content and add copyright information automatically
document.body.oncopy = function ()
{
setTimeout(
function ()
{
var text = clipboardData.getData("text");
if (text)
{
text = text + "\r\n Original text 【*****】, Reprint please keep the original link :"+location.href;
clipboardData.setData("text", text);
}
},
100
)
} This code can realize , Don't forget to write in js File or write directly in the page
<script ="text/javascript"> Code </script> Include .
After adding the above code , Someone else is on any page of your website , Copy anything with a word , The copyright information will be automatically brought when pasting .
But the downside of this code is : stay IE6 Upper test passed , And in the Firefox、Opera There is no effect on the browser .
To solve this problem , I have consulted many experts , I also checked a lot of information on the Internet , It's finally settled , Here I want to say , Du Niang is really strong .
Compatible codes are posted below :
// Copy content and add copyright information automatically
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if( window.ActiveXObject )
{
document.body.oncopy=function()
{
event.returnValue = false;
var t=document.selection.createRange().text;
var s="\r\n Original text [****] Reprint please keep the original link :"+location.href;
clipboardData.setData('Text',t+'\r\n'+s);
}
}
else
{
function addLink()
{
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var pagelink = " Original text **** Reprint please keep the original link :"+document.location.href;
var copytext = selection + pagelink;
var newdiv = document.createElement('div');
newdiv.style.position='absolute';
newdiv.style.left='-99999px';
body_element.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout
(
function()
{
body_element.removeChild(newdiv);
},0
);
}
document.oncopy = addLink;
} This code has been tested , Compatible , There may be some deficiencies , If found , Leave a comment below , Discuss together 、 improvement .
Better say something , Pay attention to the coding , If the copyright information added to the copied content is found to be garbled , You can check for coding problems yourself .
边栏推荐
- High availability solution practice of mongodb advanced applications (4)
- Troubleshooting of datanode entering stale status
- Script to view the execution of SQLSERVER database stored procedures
- Importance of ERP management system
- B. AND 0, Sum Big-Codeforces Round #716 (Div. 2)
- POC about secureworks' recent azure Active Directory password brute force vulnerability
- 根据年份获取第一天和最后一天
- MySQL transaction submission process
- Is it cost-effective to buy a long-term financial product?
- Look, this is the principle analysis of modulation and demodulation! Simulation documents attached
猜你喜欢

hands-on-data-analysis 第二单元 第四节数据可视化

Self supervised learning (SSL)

Hands on data analysis unit 2 section 4 data visualization

Why do we say that the data service API is the standard configuration of the data midrange?

Database Experiment 2 query

Online communication - the combination of machine learning and knowledge reasoning in trusted machine learning (Qing Yuan talk, issue 20, Li Bo)

Tupu software builds smart city with lightweight modeling

How to configure MySQL log management

10分钟后性能测试瓶颈调优!想进大厂这个必须会
![[qsetting and.Ini configuration files] and [create resources.qrc] in QT](/img/67/85a5e7f6ad4220600acd377248ef46.png)
[qsetting and.Ini configuration files] and [create resources.qrc] in QT
随机推荐
Here comes the official zero foundation introduction jetpack compose Chinese course!
解答01:Smith圆为什么能“上感下容 左串右并”?
Hapoxy cluster service setup
记录——kubeadm集群node节点加入
POC about secureworks' recent azure Active Directory password brute force vulnerability
Intelligent supply chain collaborative management solution for logistics industry
Jetpack compose and material you FAQs
Redis cluster operation method
Add new members to the connector family! Scenario connector helps enterprises comprehensively improve the operational efficiency of business systems
Performance test bottleneck tuning in 10 minutes! If you want to enter a large factory, you must know
[network communication -- webrtc] analysis of webrtc source code -- supplement of pacingcontroller related knowledge points
Company offensive operation guide
浅析3种电池容量监测方案
Why do we say that the data service API is the standard configuration of the data midrange?
【网络通信 -- WebRTC】WebRTC 源码分析 -- 接收端带宽估计
MySQL - reasons for using repeatable read
Hapoxy-集群服务搭建
JSON - learning notes (message converter, etc.)
Meituan Sanmian: how do you understand the principle of redis master-slave replication?
ABP framework - data access infrastructure (Part 2)