我正在通读 this article关于 Chrome 和 Firefox 中的图像粘贴。
回顾一下,Firefox 不提供有关粘贴图像的任何信息,“粘贴”事件处理程序获取一个空的 clipboardData
对象。
要解决这个问题,可以在 DOM 中放置一个不可见的 contenteditable div
并始终保持焦点,当粘贴内容时,它会触发超时,检查不可见 div 的内容以获取图像处理。
除了用 contenteditable div 替换 textarea 之外,是否有任何方法可以使用魔术 iframe 或其他东西来破解内容,从而在 Firefox 中获得粘贴图像支持?
(注:Java和Flash解决方案不在话下)
最佳答案
<div id="paste" contenteditable="true"></div>
将此项插入到您的 html 中,然后调用以下命令
var pasteDiv = $("#paste")[0];
document.body.onpaste = function (event) {
pasteDiv.focus();
//do your magic firefox here
};
onpaste
在这里触发,因为您有 contenteditable
div,然后您可以告诉 firefox 将此剪贴板数据集中在哪里。 (如果没有至少一个 contenteditable
项,onpaste
不会触发)
有关工作示例,请参阅:https://gist.github.com/4577472
关于javascript - 可以将 "paste image"支持破解到 Firefox 中的文本区域吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14151018/