Created
August 9, 2019 07:30
-
-
Save loveyunk/96ff4f7d663440ab6997d300d938e31d to your computer and use it in GitHub Desktop.
copyToClipBoard
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>copyToClipBoard</title> | |
</head> | |
<body> | |
<div class="hl7MsgBox"> | |
<span class="boxspan">1</span> | |
<br /> | |
<span class="boxspan">2</span> | |
<br /> | |
<span class="boxspan">3</span> | |
<br /> | |
<span class="boxspan">4</span> | |
<br /> | |
<span class="boxspan">5</span> | |
<br /> | |
<span class="boxspan">6</span> | |
<br /> | |
<span class="boxspan">7</span> | |
<br /> | |
<span class="boxspan">8</span> | |
</div> | |
<button class="btnCopy">Copy To Clipboard</button> | |
<br /> | |
<textarea rows="8" cols="50" placeholder="Paste text here..."></textarea> | |
<script> | |
const copyToClipBoard = str => { | |
const el = document.createElement('textarea'); | |
el.value = str; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
}; | |
document.querySelector('.btnCopy').addEventListener('click', function() { | |
var copyText = document.querySelector('.hl7MsgBox').textContent; | |
// Or... | |
//var elems = document.getElementsByClassName("hl7MsgBox"); | |
//var copyText = elems[0].textContent; | |
copyToClipBoard(copyText); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment