Adding "Read More" link to Copied Text from your Website?

Marc0

Well-known member
Registered
Joined
Jun 6, 2012
Messages
890
Points
28
How can I add "Read More link to Copied Text from your website?
Sometimes, when you need to retrieve content from a certain web page, copy and paste the content into notepad, the contents of which are usually attached to a link as Read more at: http://www.webmastersun.com/forums/21-Websites-Design . Website owners usually do this to protect content on their site as well as all copyright notices for people who want to write to get content.

Can you give me codes to do that? :eek:
 

Alex_smith

Well-known member
Registered
Joined
Dec 19, 2012
Messages
90
Points
0
Interesting question :D

If you want to do that, you will use document.body.oncopy attribute, it returns onCopy event on the current element.

The syntax is as follows:

Code:
element.oncopy = functionRef;

We'll insert a different javascript function called window.getSelection (); returns an object representing the character sequence is selected by the user.

jQuery Code

Code:
$(document).ready(function () {
    document.body.oncopy = function () {
        var body_element = document.getElementsByTagName('body')[0];
        var selection;
        selection = window.getSelection();
        var pagelink = "<br />Read more at: <a href='" + document.location.href + "'>" + document.location.href + "</a><br />";
        var copytext = selection + pagelink;
        var newdiv = document.createElement('div');
        body_element.appendChild(newdiv);
        newdiv.innerHTML = copytext;
        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {
            body_element.removeChild(newdiv);
        }, 0);
    };
});
When you insert this code into your website, then, is from now on, anyone who copy content from your website, then along with the content that they want to take the section links pointing to your site also inserted them. I hope you'll enjoy with the code that I shared with you today.

Good luck!
 
Newer Threads
Replies
26
Views
8,661
Replies
6
Views
4,215
Replies
6
Views
4,354
Recommended Threads
Replies
18
Views
7,961
Replies
1
Views
1,742
Replies
7
Views
3,889
Replies
2
Views
2,863

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top