Created
June 20, 2019 05:27
-
-
Save manchumahara/695d09e02ee892f3594b4ba7b2a66397 to your computer and use it in GitHub Desktop.
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 copyText( text ){ | |
var div = document.createElement( 'div' ); | |
div.innerHTML = text; | |
div.style.height = ''; | |
div.style.position = 'fixed'; | |
div.style.bottom = '0'; | |
div.style.left = '0'; | |
div.style.opacity = '0'; | |
div.style.display = 'block'; | |
div.style.overflow = 'hidden'; | |
div.style.zIndex = 9999999999; | |
document.body.appendChild( div ); | |
var range = document.createRange(); | |
range.selectNode(div); | |
window.getSelection().addRange(range); | |
var selection = window.getSelection(); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
var successful = false; | |
try { | |
successful = document.execCommand('copy'); | |
} catch(err) { | |
} | |
window.getSelection().removeAllRanges(); | |
div.remove(); | |
return successful; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment