美文网首页
/2016/5/31/ chrome 复制图片与剪贴板的坑

/2016/5/31/ chrome 复制图片与剪贴板的坑

作者: 不知语冰 | 来源:发表于2016-05-31 23:48 被阅读1230次

最近在试试 electron ,用到一个剪贴板的功能,也就是粘贴剪贴板中的图片,
chrome 由于有特有的 API 所以很容易就能获得剪贴板中的图片,然而用 chrome 中的复制图片功能复制的图片,虽然系统剪贴板中已经存在了,但是其还会复制一份富文本内容到剪贴板,而用 chrome 的 API 粘贴时,富文本优先级更高,所以就没法获取图片了

Paste_Image.png

只能用 event.clipboardData.getData("text/html") 或者富文本内容,然后在从下面这样的 html 代码中提取图片地址,再获取图片:

<html>
<body>
<!--StartFragment-->![](https://img.haomeiwen.com/i71097/8985e12cc656579e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)<!--EndFragment-->
</body>
</html>
```


![electron ](https://img.haomeiwen.com/i71097/ee21d7981ca735e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

相关文章

网友评论

      本文标题:/2016/5/31/ chrome 复制图片与剪贴板的坑

      本文链接:https://www.haomeiwen.com/subject/mochdttx.html