Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rank-math domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u996806617/domains/vidyut.net/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rank-math-pro domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u996806617/domains/vidyut.net/public_html/wp-includes/functions.php on line 6114
Add source url to content copied from your site - Vidyut

Add source url to content copied from your site

Ever wonder how the url gets added when you copy something on some websites? There are plugins and websites that do it (for money or registration), but they also appear to track clicks, so I was a bit paranoid. It isn’t so difficult and is very useful.

Basically, what happens is that whenever content from the page is copied to the clipboard, the url (or other text you want) gets added to the copied content automatically. This is useful if someone copies content from your website – often for email (as it turns out in my logs). Your page where it got copied from gets added automatically.

I have also found it useful when I want to tweet quotes from an article on the site. Instead of copying the quote and url separately, selecting the text I want gives me the content for the tweet.

Here is the javascript I am using. Feel free to edit what will be added to the content (change the square brackets before using – the code isn’t getting posted as content as javascript).

[script type="text/javascript"]
function addLink() {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var pagelink = "
Source: "+document.location.href; // change this if you want
var copytext = selection + pagelink;
var newdiv = document.createElement('div');
newdiv.style.position='absolute';
newdiv.style.left='-99999px';
body_element.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function() {
body_element.removeChild(newdiv);
},0);
}
document.oncopy = addLink;
[/script]


Posted

in

by

Tags:

Comments

One response to “Add source url to content copied from your site”

  1. Andrews32 Avatar

    Thanx very much!!! Your script is more useful than Tynt(.com)

Leave a Reply

Your email address will not be published. Required fields are marked *