Skip to content

Instantly share code, notes, and snippets.

@Inontran
Created August 5, 2020 05:15
Show Gist options
  • Select an option

  • Save Inontran/49f6485ec2394b582752822568b358ae to your computer and use it in GitHub Desktop.

Select an option

Save Inontran/49f6485ec2394b582752822568b358ae to your computer and use it in GitHub Desktop.
скопировать текст в буфер обмена
$('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