[转][Chrome]浏览器粘贴行为
<html>
<head>
<meta charset="UTF-8">
<title>test chrome paste image</title>
<!-- https://www.zhihu.com/question/20893119/answer/19452676 -->
<style>
DIV#editable {
width: 400px;
height: 300px;
border: 1px dashed blue;
}
</style>
<script type="text/javascript">
window.onload=function() {
function paste_img(e) {
if ( e.clipboardData.items ) {
// google-chrome
//alert('support clipboardData.items(chrome ...)');
var ele = e.clipboardData.items
for (var i = 0; i < ele.length; ++i) {
if(ele[i].kind == 'string' && ele[i].type == 'text/plain') {
ele[i].getAsString(function(text){
console.log(text)
})
}
else if ( ele[i].kind == 'file' && ele[i].type.indexOf('image/') !== -1 ) {
var blob = ele[i].getAsFile();
window.URL = window.URL || window.webkitURL;
var blobUrl = window.URL.createObjectURL(blob);
console.log(blobUrl); var new_img= document.createElement('img');
new_img.setAttribute('src', blobUrl);
var new_img_intro = document.createElement('p');
new_img_intro.innerHTML = 'the pasted img url(open it in new tab): <br /><a target="_blank" href="' + blobUrl + '">' + blobUrl + '</a>'; document.getElementById('editable').appendChild(new_img);
document.getElementById('editable').appendChild(new_img_intro);
}
}
} else {
alert('non-chrome');
}
}
document.getElementById('editable').onpaste=function(){paste_img(event);return false;};
} </script>
</head>
<body >
<h2>test image paste in browser</h2>
<div id="non-editable" >
<p>copy the following img, then paste it into the area below</p>
<!--<img src="./128.png" />-->
</div>
<div id="editable" contenteditable="true" >
<p>this is an editable div area</p>
<p>paste the image into here.</p>
</div>
</body>
</html>
本文来自:https://www.zhihu.com/question/20893119/answer/19452676
经测试,仅支持 Chrome 浏览器,可支持 文字、图片、Excel 粘贴。
[转][Chrome]浏览器粘贴行为的更多相关文章
- Chrome浏览器快捷键大全(新加了其他一些浏览器的独有)
官方快捷键文档: https://support.google.com/chrome/answer/157179?hl=zh-Hans&ref_topic=14676 浏览器标签页和窗口快 ...
- 让chrome浏览器变成在线编辑器
在大部分人眼里,技术宅给人的印象是沉默寡言,总摸不透他心里想些什么,彼此都保持距离.作为半个程序员,我觉得真正的技术宅大部分时间都在找乐子,鼓捣各种想法,和大部分人的极客心理是一样的,程序员也还爱讲笑 ...
- Chrome浏览器的密码隐患
谷歌浏览器的密码填充使得登陆账号很方便 但在你了解了Chrome的密码特性机制后,你该做点什么了 1.如何查看已保存的密码 Chrome 密码管理器的进入方式:右侧扳手图标→设置→显示高级设置→密码和 ...
- 详解googe Chrome浏览器(理论篇)
开篇概述 1详解google Chrome浏览器,这个标题似乎抽象了一些,我想应该把它拆分成如下几个问题,也许会更加理解一些. 问题1:目前开发中,主选浏览器有Google Chrome,IE,Fir ...
- 详解Google Chrome浏览器(操作篇)(一)
开篇概述 在上篇博客中详解Google Chrome浏览器(理论篇)一文中,主要讲解了Chrome 搜索引擎使用.Chrome安装和基本操作.Chrome 基本架构.多线程等原理性问题,这篇将重点讲解 ...
- Chrome浏览器读写系统剪切板
IE浏览器支持直接读写剪切板内容: window.clipboardData.clearData(); window.clipboardData.setData('Text', 'abcd'); 但是 ...
- chrome浏览器下JavaScript实现clipboard时无法访问剪切板解决方案
在用JavaScript实现某个简单的复制到剪切板功能的时候,会考虑一下浏览器兼容性,主要是重点在IE和FireFox,把这个两个浏览器搞定后,基本上其他浏览器也不用太操心了,Chrome也一样,没出 ...
- 浅谈Google Chrome浏览器(操作篇)(上)
开篇概述 在上篇博客中详解Google Chrome浏览器(理论篇)一文中,主要讲解了Chrome 搜索引擎使用.Chrome安装和基本操作.Chrome 基本架构.多线程等原理性问题,这篇将重点讲解 ...
- 浅谈Google Chrome浏览器(理论篇)
注解:各位读者,经博客园工作人员反馈,hosts涉及违规问题,我暂时屏蔽了最新hosts,若已经获取最新hosts的朋友们,注意保密,不要外传.给大家带来麻烦,对此非常抱歉!!! 开篇概述 1.详解g ...
随机推荐
- Java——线程间通信
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- AFNetworking 遇到错误 Code=-1016 "Request failed: unacceptable content-type: text/plain"
在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可): AFHTTPRequestOperationManager *manager = [AF ...
- Android下打印堆栈的两种方法
1. for(StackTraceElement i:Thread.currentThread().getStackTrace()){ System.out.println(i); } 2. Log. ...
- scss学习笔记
1.引用父选择符: & #main { color: black; a { font-weight: bold; &:hover { color: red; } } } 2.font: ...
- 计算 S=a+aa+aaa+aaaa+a.......a【转载】
package java算法; import java.util.Scanner; /* * 计算 S=a+aa+aaa+aaaa+a.......a */ public class numadd { ...
- [python]自问自答:python -m参数? ( python3.7 版本 )
最近在看Python代码的时候看到了一种形式, 即 python -m 这种形式, 查了一些博客,发现了一篇写的还不错,转载了过来,不过那里面写的是Python2.7的环境和python3 ...
- Luogu 3245 大数
Luogu 3245 大数 开始就想 \(10\) 进制 \(hash\) ,\(Hash(r)\equiv Hash(l-1)\cdot 10^{r-l+1}\) ,感觉没什么美妙的性质啊... 然 ...
- 实验吧—隐写术——WP之 欢迎来到地狱
解压压缩包后出现三个文件.jpg .zip .docx 发现图片打开不显示,用winhex打开发现缺少文件头,将jpg的文件头补上 保存后图片可以打开 是一个百度网盘的链接,注意l和1的区别,网盘里是 ...
- 2018-2019-2 网络对抗技术 20165212 Exp4 恶意代码分析
2018-2019-2 网络对抗技术 20165212 Exp4 恶意代码分析 原理与实践说明 1.实践目标 监控你自己系统的运行状态,看有没有可疑的程序在运行. 分析一个恶意软件,就分析Exp2或E ...
- test20180919 递归问题
题意 定义 \[ f(n)=\left\{ \begin{array}{} 1 & n=1\\ f(n-f(f(n-1)))+1 & n>1 \end{array} \right ...