Created
November 9, 2015 10:52
-
-
Save SergSlon/c38bf4e987b24c005fe4 to your computer and use it in GitHub Desktop.
Clipboard: добавляет ссылку на сайт
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
| jQuery(function($){ | |
| $(document).on("copy", function () { | |
| var selection, html = ""; | |
| if (window.getSelection || document.getSelection) { | |
| selection = window.getSelection ? window.getSelection() : document.getSelection(); | |
| if (selection.rangeCount) { | |
| html = document.createElement("div"); | |
| for (var i = 0, n = selection.rangeCount; i < n; ++i) { | |
| html.appendChild(selection.getRangeAt(i).cloneContents()); | |
| } | |
| html = html.innerHTML; | |
| } | |
| } else if (document.selection && document.selection.type == "Text") { | |
| selection = document.selection.createRange(); | |
| html = selection.htmlText; | |
| } | |
| if (!html) { | |
| return; | |
| } | |
| html += "<br>\n<br>\n" + document.location.href; // magic here | |
| var container = $("<div style=\"position:absolute;left:-99999px\"></div>").appendTo("body"); | |
| container.html(html); | |
| selection.selectAllChildren(container.get(0)); | |
| setTimeout(function() { | |
| container.remove(); | |
| }, 0); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment