Skip to content

Instantly share code, notes, and snippets.

@hallison
Created July 25, 2020 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallison/9dc0ecdec3190de9a115405f85ba654c to your computer and use it in GitHub Desktop.
Save hallison/9dc0ecdec3190de9a115405f85ba654c to your computer and use it in GitHub Desktop.
Copy and paste with footer information (from https://braziljournal.com/)
$(document).ready(function() {
$(document).on('copy', function () {
var selection = window.getSelection();
var copyFooter = '<br><br>Leia mais em <a href="' + document.location.href + '">' + document.location.href + '</a>';
var copyHolder = $('<div>', {
html: (selection + '').substring(0, 140) + '...' + copyFooter,
style: {
position: 'absolute',
left: '-99999px'}
}
);
$('body').append(copyHolder);
selection.selectAllChildren(copyHolder[0]);
window.setTimeout(function() {
copyHolder.remove();
}, 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment