开发者

Branding copy paste from browser

开发者 https://www.devze.com 2023-01-25 08:29 出处:网络
I saw this http://www.tynt.com/... and I loved their services. only I\'m trying to develop something custom for me.. They library is large. I\'m trying to do this for the past 10 hours.

I saw this http://www.tynt.com/... and I loved their services. only I'm trying to develop something custom for me.. They library is large. I'm trying to do this for the past 10 hours.

Here where I got:

$(document).ready(function() {
    var ctrlDown = false;
    var ctrlKey = 17, vKey = 86, cKey = 67;

    $(document).keydown(function(e) {
        if (e.keyCode == ctrlKey) {
            if (getSelText() != null)
            { alert(getSelText()); }

            ctrlDown = true;
        }
    }).keyup(function(e) {
        if (e.keyCode == ctrlKey) {
            ctrlDown = false;
            //alert("Control is NOOOOOOOOOOOOOT  pressed");
        }
    });

    $(".no-copy-paste").keydown(function(e) {
        if (ctrlDown && (e.keyCode == vKey || e.keyCode == cKey)) return false;
    });
});

function getSelText() {
    var txt = '';
    if (window.getSelection) {
        txt = window.getSelection();
        if (txt.type == "Range") {
            return txt + " <br /><br /><a href='" + window.location.pathname + "'>View Original Link</a>";
        }
    }
    else if (document.getSelection) {
        txt = document.getSelection();
        if (txt.type == "Range") {
            return txt + " <br /><br /><a href='" + window.location.pathname + "'>View Original Link</a>";
        }
    }
    else if (document.selection) {
        txt = document.selection.createRange().text;
        if (txt.type == "Range") {
            return txt + " <br /><br />开发者_StackOverflow中文版;<a href='" + window.location.pathname + "'>View Original Link</a>";
        }
    }
    else return;

    return null;
}

The two issues I have:

  1. the appended text only worked if I had this line alert(getSelText()); ... don't know really why.
  2. the appended text is not formatted in HTML

I have looked into zeroclipboard, but it uses flash which is arrrah...

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消