欢迎光临
我们一直在努力

wordpress复制网页内容自动添加版权信息

将代码添加到网页head 头部,WordPress主题可以将代码添加到头部模板header.php:<?php wp_head(); ?>,上面即可。

不要忘记将代码放在:

<script ="text/javascript"> 代码 </script>

代码一:

function addLink() {
    var selection = window.getSelection();
    pagelink = ". 原文出自[知更鸟] 转载请保留原文链接: " + document.location.href;
    copytext = selection + pagelink;
    newdiv = document.createElement('div');
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';
    document.body.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    selection.selectAllChildren(newdiv);
    window.setTimeout(function () {
        document.body.removeChild(newdiv);
    }, 100);
}
document.oncopy = addLink;

代码二:

function addLink() {
    var body_element = document.body;
    var selection;
    selection = window.getSelection();
    if (window.clipboardData) { // Internet Explorer
        var pagelink ="\r\n\r\n 原文出自[ 知更鸟 ] 转载请保留原文链接: "+document.location.href+"";
        var copytext = selection + pagelink;
        window.clipboardData.setData ("Text", copytext);
        return false;
    } else {
        var pagelink = " 原文出自[ 知更鸟 ] 转载请保留原文链接: "+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;

添加以上代码后,别人在你网站复制任何文字内容,粘贴时都会自动带上版权信息,使用时修改其中的版本信息,貌似不支持低版本IE。

修改模板后,记得将模板编码改为:UTF-8 无BOM(无签名),否则提示中的汉字会乱码,建议使用专门的编辑工具,比如:Notepad++(免费)编辑修改主题模板文件。

赞(0) 打赏
未经允许不得转载:WORDPRESS大侠 » wordpress复制网页内容自动添加版权信息

评论 抢沙发

评论前必须登录!

 

更好的WordPress主题

支持快讯、专题、百度收录推送、人机验证、多级分类筛选器,适用于垂直站点、科技博客、个人站,扁平化设计、简洁白色、超多功能配置、会员中心、直达链接、文章图片弹窗、自动缩略图等...

联系我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册