如何在跨浏览器中读取剪贴板数据? [英] How to read clipboard data in cross browser?

查看:24
本文介绍了如何在跨浏览器中读取剪贴板数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
使用 FireFox 将文本复制/放在剪贴板上,Safari 和 Chrome
如何在 JavaScript 中复制到剪贴板?

场景:我复制了一些内容(从记事本或 word 中)并想将其粘贴到我的 iframe 中.在粘贴之前,我想操作剪贴板内容.在 IE 中,我可以使用 window.clipboardData.getData("Text");如何在其他浏览器(FF/chrome 和 safari)中读取剪贴板数据

scenario: I copied some content (either from notepad or word) and want to paste it in my iframe. On before pasting i want to manipulate the clipboard content. In IE i can do it with window.clipboardData.getData("Text"); How to read the clipboard data in other browsers (FF/chrome and safari)

推荐答案

当用户明确触发粘贴(例如,使用 Ctrl-V 或编辑或上下文菜单).

You'll only be able to do this in most browsers when the user explicitly triggers a paste (for example, by using Ctrl-V or the edit or context menus).

在 Firefox 和 Opera 中,您需要使用一种 hack,例如我在此处概述的一种:JavaScript 获取粘贴事件的剪贴板数据(跨浏览器).

In Firefox and Opera you'll need to use a hack, such as the one I outlined here: JavaScript get clipboard data on paste event (Cross browser).

在 Internet Explorer、Safari 和 Chrome 中,您可以在 IE 中使用 window.clipboardDatapaste 事件的 clipboardData 在粘贴过程中直接访问剪贴板WebKit 中的代码> 属性.更多信息可以在 Apple 开发者网站.

In Internet Explorer, Safari and Chrome, you can access the clipboard directly during a paste using window.clipboardData in IE and the paste event's clipboardData property in WebKit. More information can be found on the Apple developer site.

这篇关于如何在跨浏览器中读取剪贴板数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆