当前位置:首页>wordpress教程> WordPress防复制代码

WordPress防复制代码

通过下面的JS代码,可以有效地防止别人直接复制拷贝你的文章,用frame标签引用你的文章时,会自动跳转到文章正常链接,同时禁止右键菜单。使用方法一: 打开当前主题头部模板header.php找到:将下面代码添加到后面: 123456789101112131415161718192021222324<

通过下面的JS代码,可以有效地防止别人直接复制拷贝你的文章,用frame标签引用你的文章时,会自动跳转到文章正常链接,同时禁止右键菜单。

WordPress防复制代码
使用方法一:
打开当前主题头部模板header.php找到:将下面代码添加到后面:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script>
// 禁止右键
document.oncontextmenu = function() {
    return false
};
// 禁止图片拖放
document.ondragstart = function() {
    return false
};
// 禁止选择文本
document.onselectstart = function() {
    if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") return false;
    else return true;
};
if (window.sidebar) {
    document.onmousedown = function(e) {
        var obj = e.target;
        if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") return true;
        else return false;
    }
};
// 禁止frame标签引用
if (parent.frames.length > 0) top.location.replace(document.location);
</script>

使用方法二:
上面的方法查看源代码时有些乱,可以在当前主题目录新建一个名称为copyright.js文件,将下面代码添加进去:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 禁止右键
document.oncontextmenu = function() {
    return false
};
// 禁止图片拖放
document.ondragstart = function() {
    return false
};
// 禁止选择文本
document.onselectstart = function() {
    if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") return false;
    else return true;
};
if (window.sidebar) {
    document.onmousedown = function(e) {
        var obj = e.target;
        if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") return true;
        else return false;
    }
};
// 禁止frame标签引用
if (parent.frames.length > 0) top.location.replace(document.location);

然后再将下面代码添加到当前主题函数模板functions.php的最后:

1
2
3
4
5
6
7
function copyrightpro_scripts() {
    wp_enqueue_script( ‘copyright’, get_template_directory_uri() . ‘/copyright.js’, array(),  false );
}
 
if (! current_user_can(‘level_10’) ) {
add_action( ‘wp_enqueue_scripts’, ‘copyrightpro_scripts’ );
}

代码中加了判断,管理员登录状态一下,防复制代码无效。
当然上面的方法,也只是忽悠一下小白,浏览器禁用JavaScript后,将失去效果。

JS代码提取自:CopyRightPro插件

温馨提示:本文最后更新于 2023-12-09 15:47 ,某些文章具有时效性,若有错误或已失效,请在下方留言或联系QQ115904045
声明 本站上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。无意侵害您的权益,请发送邮件至 [email protected] 或点击右侧 私信:尚艺网络 反馈,我们将尽快处理。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress判断当前文章的分类

2023-12-9 15:47:03

wordpress教程

WordPress如何设置摘要字数

2023-12-9 15:47:05

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
联系我们