• JS实现复制网页内容自动加入版权内容代码和原文链接


    JS实现复制网页内容自动加入版权内容代码和原文链接

    实现代码:在body内放入如下代码即可:

    <script type="text/javascript">
    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=" 原文链接:"+location.href;
            clipboardData.setData('Text',t+'
    '+s);
        };
    }else{
        function addLink(){
            var body_element = document.getElementsByTagName('body')[0];
            var selection;
            selection = window.getSelection();
            var pagelink = " 原文链接:"+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;
    }
    </script>
  • 相关阅读:
    leetcode bugfree note
    leetcode 419
    leetcode 165
    leetcode 155
    leetcode 204
    leetcode 28
    将二叉搜索树转为有序双向链表
    leetcode 397
    ABAP 动态内表创建/赋值
    ABAP 屏幕下拉框值根据选择框填值赋值
  • 原文地址:https://www.cnblogs.com/zdz8207/p/js-oncopy.html
Copyright © 2020-2023  润新知