Last active
December 27, 2015 06:49
-
-
Save lsauer/7284215 to your computer and use it in GitHub Desktop.
JavaScript : Copy text to the clipboard, without Flash and securely with subsequent url-change
This file contains hidden or 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
//www.lsauer.com, lo sauer 2013 | |
//see: http://www.lsauer.com/2012/05/javascript-copy-text-to-clipboard.html | |
var keypressHandlerForwardLocation = function(evt){ | |
if(evt instanceof KeyboardEvent && evt.target instanceof HTMLElement | |
&& evt.keyCode == 99 && evt.ctrlKey==true && evt.target != null | |
&& (evt.target.innerText || evt.target.value).Trim().substr(0,4) == "http"){ | |
cancelBubble = true; | |
window.location = (evt.target.innerText || evt.target.value).Trim(); | |
} | |
} | |
//attach | |
keypressHandlerForwardLocation.attached | |
|| ((keypressHandlerForwardLocation.attached = true) && window.addEventListener("keypress", keypressHandlerForwardLocation)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment