Read More link to Copied Text... the line breaks and formatting are ignored

Go down

Read More link to Copied Text... the line breaks and formatting are ignored

Post by Ahmed.K on June 14th 2014, 9:29 am


I am using this code to add a read more link to my copied text but the line breaks and formatting are ignored:

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);
    };
});

How to preserve them?

There is a good code: http://jsfiddle.net/acdcjunior/XKjNz/9/
But doesn't work here.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum