2013-03-14 22 views
0

對不起,因爲我是波斯人,我不知道英語太多! 我希望把這段代碼在我的網頁:給一個頁面免除一個埃萊曼的影響

function addLink() { 
    var body_element = document.getElementsByTagName('body')[0]; 
    var selection; selection = window.getSelection(); 
    var pagelink = "<br /><br /> original: <a href='"+document.location.href+"'>"+document.location.href+"</a>"; 
    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; 

但這種代碼的行動對所有的標籤,我想這樣做,在「文本域」不如行動! 我非常感謝,如果你幫我 :)

+1

我不明白這一點 - 什麼是你想用這個腳本才達到? – WTK 2013-03-14 10:04:19

回答

0

測試tagNameaddlink()

document.body.addEventListener('copy', function (e) { 
    if (e.target.tagName === 'textarea') { 
     return; 
    } 
    addlink() 
} 
+0

我該如何使用它? – user2169140 2013-03-14 13:35:11

+0

在我的代碼中用'document.oncopy = addLink;'代替行。 – LotusH 2013-03-14 22:00:07

+0

非常感謝。但是當我測試新代碼時,它不起作用! – user2169140 2013-03-16 12:52:42

相關問題