Created
February 27, 2017 13:44
-
-
Save IgnacioGaldames/41cba019899fb9575a72632480766502 to your computer and use it in GitHub Desktop.
Copyright webpages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addLink() { | |
var body_element = document.getElementsByTagName('body')[0]; | |
var selection; | |
selection = window.getSelection(); | |
// change this if you want | |
var pagelink = "<br><br>Fuente: myFuente - <a href='"+document.location.href+"'>"+document.location.href+"</a><br>"; | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment