Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function copyToClipboard(id, isHTML = true) {
- /* copy text to clipboard by element id set isHTML to false to copy plain text to the clipboard
- the default copy to the clipboard is HTML format */
- function handler (event){
- if(isHTML){
- event.clipboardData.setData('text/html', $("#" + id).html());
- }
- else{
- event.clipboardData.setData('text/plain', $("#" + id).text());
- }
- event.preventDefault();
- document.removeEventListener('copy', handler, true);
- }
- document.addEventListener('copy', handler, true);
- document.execCommand('copy');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement