Created
October 11, 2016 18:10
-
-
Save bradlis7/c4ccef6d3833ea07b2fffbedff6fa9e9 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
/// link-copy-jquery.js | |
/// This makes all links with class .copylink Copy their link to the clipboard, instead of opening the links. It | |
/// attempts to use browser capabilities, but falls back to a popup prompt that can be copied if it fails. | |
/// | |
/// Thanks to these answers on stackoverflow: https://stackoverflow.com/a/6055620/179311 https://stackoverflow.com/a/30810322/179311 | |
/// Created By: Brad Landis <[email protected]> | |
$(".copylink").click(function(e) { | |
e.preventDefault(); | |
var value = $(this)[0].href; | |
var input = $("<input type='text' style='position: fixed; top: -1000px; left: -1000px;'>").val(value).appendTo("body"); | |
input.select(); | |
var success = false; | |
try { | |
success = document.execCommand('copy'); | |
} catch (e) { } | |
if (success) { | |
alert("The access link has been copied to your clipboard:\n" + value); | |
} else { | |
window.prompt("Copy this link to your clipboard:", value); | |
} | |
input.remove(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment