怎么实现 复制自动添加版权信息随机显示位置    而不是显示在文章最下面
//复制内容自动添加版权信息
var thehits=document.getElementById("thehit");
if (thehits!=null){
thehits.innerHTML="22936";
}
document.body.oncopy = function ()
{
setTimeout(
function ()
{
var text = clipboardData.getData("text");
if (text)
{
text = text + "本文转自,原文地址:"+location.href;
clipboardData.setData("text", text);
}
},
100
)
}
window.onload = function()
{
this.focus();
}

解决方案 »

  1.   

    不知道楼主是不是这个意思???var thehits=document.getElementById("thehit");
    if (thehits!=null){
    thehits.innerHTML="22936";
    }
    document.body.oncopy = function ()
    {
    setTimeout(
    function ()
    {
    var text = clipboardData.getData("text");
    if (text)
    {
    var len=parseInt(text.length/2);
    text = text.substring(0,len) + "本文转自,原文地址:"+location.href+text.substring(len+1,text.length);clipboardData.setData("text", text);
    }
    },
    100
    )
    }
    window.onload = function()
    {
    this.focus();
    }
      

  2.   


    学习,我在想是不是可以加一个随机数,用text.length与随机数结合来取位置
      

  3.   

    那你设置个随机函数,弄成百分比的形式Math.random()参数一个随机数,然后插入到产生随机数百分比的位置
      

  4.   

    建议楼主放弃这个功能。这个防不了自动采集程序,只能给普通用户增加麻烦,你这样跟用户过不去,还指望用户再光顾你的网站吗?真要做,这个可以通过length属性先取出字串的长度,然后用随机数函数乘以这个长度,就得到一个在长度之内的随机数了,用此随机数拆分字串成前后两部分,中间加上你的版权信息就可以了。