使用jquery检测从网页复制的内容 [英] detect what is copied from webpage with jquery
本文介绍了使用jquery检测从网页复制的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对jquery有疑问。
I have a question about jquery.
我知道我们可以用这样的jquery检测副本:
I know we can detect copy with jquery like this :
$("#textA").bind('copy', function() {
$('span').text('copy behaviour detected!')
});
$("#textA").bind('paste', function() {
$('span').text('paste behaviour detected!')
});
$("#textA").bind('cut', function() {
$('span').text('cut behaviour detected!')
});
但是,我想知道什么是完全复制的?
But , i want to know what is exactly copied ?
例如,用户复制一个盒子的值,我需要得到并拥有该值。
for example, user copy the value of one box, i need to get and have that value .
如何用jquery做到这一点?
How to do this with jquery?
推荐答案
你可以使用这个
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
$(document).keypress("c",function(e) {
if(e.ctrlKey)
alert(getSelectionText());
});
这应该是有效的
这篇关于使用jquery检测从网页复制的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文