标签:javascript paste google-chrome copy clipboard
You can capture an image.我试图找出如何捕获文本.我猜是因为安全原因没有,但我想确定一下.
这个东西还有参考吗? window.Clipboard对象不是v8引擎的一部分,它是chrome浏览器的一部分,我无法找到它的官方文档.
解决方法:
在您链接的代码中,有一个pasteHandler函数,其中包含以下内容:
// Get the items from the clipboard
var items = e.clipboardData.items;
if (items) {
// Loop through all items, looking for any kind of image
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") !== -1) {
// We need to represent the image as a file,
var blob = items[i].getAsFile();
// and use a URL or webkitURL (whichever is available to the browser)
// to create a temporary URL to the object
var URLObj = window.URL || window.webkitURL;
var source = URLObj.createObjectURL(blob);
// The URL can then be used as the source of an image
createImage(source);
}
}
}
Chrome开发者框架告诉我items [i]是DataTransferItem (reference)
在参考页面上,我看到了一个kind属性和一个getAsString()方法.后者似乎需要一个回调函数来接收文本作为参数.因此,要使用上述脚本处理文本值,您可以修改我链接的部分,如下所示:
// Get the items from the clipboard
var items = e.clipboardData.items;
if (items) {
// Loop through all items, looking for any kind of image
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") !== -1) {
// We need to represent the image as a file,
var blob = items[i].getAsFile();
// and use a URL or webkitURL (whichever is available to the browser)
// to create a temporary URL to the object
var URLObj = window.URL || window.webkitURL;
var source = URLObj.createObjectURL(blob);
// The URL can then be used as the source of an image
createImage(source);
}
if (items[i].kind === "string"){
items[i].getAsString(function(s) {
alert(s);
});
}
}
}
标签:javascript,paste,google-chrome,copy,clipboard 来源: https://codeday.me/bug/20191005/1855972.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。