所以我试图收集人们在我们网站上选择的内容。目前,它无处不在,我不希望这样。如果他们在某个 DIV 中选择,我只想要它。
它基本上是对我找到的脚本的简单修改。
<script type="text/javascript">
function appendCopyright() {
var theBody = document.getElementsByClassName("sbReview")[0];
var selection;
selection = window.getSelection();
var copyrightLink = '<br /><br /> - Read more at: <a href="'+document.location.href+'">'+document.location.href+'</a><br />©2012 <? printf($product. ' & ' .$spOrganization); ?>';
var copytext = selection + copyrightLink;
var extra = document.createElement("div");
extra.style.position="absolute";
extra.style.left="-99999px";
theBody.appendChild(extra);
extra.innerHTML = copytext;
selection.selectAllChildren(extra);
window.setTimeout(function() {
theBody.removeChild(extra);
},0);
}
document.oncopy = appendCopyright;
我尝试修改selection = window.getSelection();
但它只是破坏了它:(
基本上,我想要上面的代码,只能在某个 div 中工作,而不是整个body