Created
August 5, 2020 05:15
-
-
Save Inontran/49f6485ec2394b582752822568b358ae to your computer and use it in GitHub Desktop.
скопировать текст в буфер обмена
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
| $('body').on('click', '.clipboard', function(event){ | |
| event.preventDefault(); | |
| var text_source = $(this).attr('data-source'); | |
| var text = $(text_source).text(); | |
| var $temp = $("<input>"); | |
| $("body").append($temp); | |
| $temp.css({ | |
| position: 'absolute', | |
| zIndex: '-1000' | |
| }); | |
| $temp.val($(text_source).text()).select(); | |
| try { | |
| var successful = document.execCommand('copy'); | |
| var msg = successful ? 'successful' : 'unsuccessful'; | |
| console.debug('Copy text command was ' + msg); | |
| } catch(err) { | |
| console.debug('Oops, unable to copy'); | |
| } finally{ | |
| $temp.remove(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment