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:
- the appended text only worked if I had this line
alert(getSelText());
... don't know really why. - the appended text is not formatted in HTML
I have looked into zeroclipboard, but it uses flash which is arrrah...
Thanks.
精彩评论