The following post shows a simple JavaScript code to add link for reference when someone copies text from your website.
You can just copy paste the following code to your webpage and add the link to the copied content.
$(document).on('copy', function(e) { var sel = window.getSelection(); var url = window.location.href; var copyFooter = "<br /><br /><a href='" + url + "'>" + url + "</a>"; var copyHolder = $('<div>', { html: getSelectionHtml() + copyFooter, style: { position: 'absolute', left: '-99999px' } }); $('body').append(copyHolder); sel.selectAllChildren(copyHolder[0]); window.setTimeout(function() { copyHolder.remove(); }, 0); }); function getSelectionHtml() { var html = ""; if (typeof window.getSelection != "undefined") { var sel = window.getSelection(); if (sel.rangeCount) { var container = document.createElement("div"); for (var i = 0, len = sel.rangeCount; i < len; ++i) { container.appendChild(sel.getRangeAt(i).cloneContents()); } html = container.innerHTML; } } else if (typeof document.selection != "undefined") { if (document.selection.type == "Text") { html = document.selection.createRange().htmlText; } } return html; }
Follow the following video for complete guidance :
In this article, we will build a simple calculator using JavaScript that can carry out…
In honor of Girls in ICT Day, the Tech Bloggers Association of Nepal (TBAN) proudly…
In the ever-evolving landscape of journalism, the emergence of Artificial Intelligence (AI) is reshaping traditional…
App Created by Bishow Bhasa Campus Korean Language HOD, Mr. Thaneshwor Banjade with over 20…
A recent roundtable discussion hosted by the South Asia Watch on Trade, Economics, and Environment…
In the ever-evolving world of technology, our smartphones have become indispensable companions, particularly the iconic…
This website uses cookies.