娱乐html
<head><title>防复制链接示例</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.protected-link {
color: #0066cc;
text-decoration: none;
font-weight: bold;
}
</style>
</head>
<body>
<h1>受保护的链接(无法复制)</h1>
<!-- 这里是你的受保护链接(直接在HTML中写入) -->
<a class="protected-link" href="https://www.example.com">重要链接(点击访问)</a>
<p>尝试复制这个链接会发现无法选中或复制</p>
<!-- 防复制JavaScript代码 -->
<script>
document.addEventListener('DOMContentLoaded', function() {
// 阻止选择文本
document.addEventListener('selectstart', function(e) {
if (e.target.tagName === 'A') {
e.preventDefault();
}
});
// 阻止右键菜单
document.addEventListener('contextmenu', function(e) {
if (e.target.tagName === 'A') {
e.preventDefault();
}
});
// 阻止键盘复制快捷键
document.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
const selection = window.getSelection();
if (selection.toString().includes('http')) {
e.preventDefault();
}
}
});
// 保护所有链接
const links = document.getElementsByTagName('a');
for (let link of links) {
link.setAttribute('data-href', link.href); // 保存原始链接
link.href = 'javascript:void(0)';
link.addEventListener('click', function() {
window.location.href = this.getAttribute('data-href');
});
}
});
</script>
</body> 感谢分享 进不去了
页:
[1]