My script won't work in IE (even 9)? simple javascript to change copy text

So, one day I was browsing the internet and I was copying a piece of text " my cool text " and pasting it into facebook, only to see that it changed it to " my cool text - More in URL ", I was thrilled! It's amazing!

So, I did a bit of research and found some tutorials, etc. I took my own to convert it to a custom plugin with dozens of options, and it outputs this (or similar based on options):

function copyCopyright() {
    var theBody = document.getElementsByTagName("body")[0];
    var selection;
    selection = window.getSelection();
    var copyrightLink = '<br /><br />Read more at: '+document.location.href+'<br /> &copy;2012  ';
    var copytext = selection + copyrightLink;
    var extraDiv = document.createElement("div");
    extraDiv.style.position="absolute";
    extraDiv.style.left="-99999px";
    theBody.appendChild(extraDiv);
    extraDiv.innerHTML = copytext;
    selection.selectAllChildren(extraDiv);
    window.setTimeout(function() {
        theBody.removeChild(extraDiv);
    },0);
}
document.oncopy = copyCopyright;​

      

works GREAT in Chrome and Firefox etc. But due to COURSE, it doesn't work in IE (even IE9!). I'm new to Javascript, especially hunting for IE problems with it.

Is there a function or method or something above this IE just won't recognize that I have to look for an alternative path?

+2


source to share


1 answer


IE needs

document.body.oncopy=copyCopyright

      



added to your onload event. (body does not exist before loading)

+4


source







All Articles