Created
November 9, 2015 10:52
-
-
Save SergSlon/c38bf4e987b24c005fe4 to your computer and use it in GitHub Desktop.
Revisions
-
SergSlon renamed this gist
Nov 9, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
SergSlon created this gist
Nov 9, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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); }); });