Skip to content

Instantly share code, notes, and snippets.

@lsauer
Last active December 27, 2015 06:49
Show Gist options
  • Save lsauer/7284215 to your computer and use it in GitHub Desktop.
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
//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