添加副本&将功能粘贴到webapp的自定义菜单中 [英] Adding copy & paste functionalities to a custom menu of a webapp

查看:107
本文介绍了添加副本&将功能粘贴到webapp的自定义菜单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个包含文本编辑器的Web应用程序。它是用HTML5 + Javascript编写的。



我们成功地为我们的网络应用添加了一个自定义菜单,但是我们还没有成功添加副本&粘贴功能,如Google文档中所示。根据我们的理解,这可以使用可以访问OS剪贴板的Flash来实现。但是,我们希望避免使用该技术并使用替代方案 - 我认为Google也不会使用Flash。



任何人都可以指出我们采用有效的替代方法吗?



谢谢。

解决方案

W3C有一个工作草案< a href =http://www.w3.org/TR/clipboard-apis/#fire-a-clipboard-event =nofollow noreferrer>剪贴板API 。 。


We are working on a web application which includes a text editor. It's written in HTML5 + Javascript.

We successfully added a custom menu to our web app, but we have not succeeded in adding copy & paste functionalities as in Google Docs. To our understanding, this can be achieved using Flash which can access the OS clipboard. However, we would like to avoid that technology and use an alternative - I don't think that Google uses Flash either.

Can anybody point us to a valid alternative approach?

Thanks.

解决方案

W3C has a working draft for a Clipboard API. It's not hugely supported yet but it might be usable in the future. You'll have to take a closer look at what's not supported. An example from the W3C spec seems pretty simple:

var pasteEvent = new ClipboardEvent('paste', { bubbles: true, cancelable: true, dataType: 'text/plain', data: 'My string' } );
document.dispatchEvent(pasteEvent);

An article from MDN seems to take a different approach, using XPCOM Components, but if I'm not mistaken that will only work in FireFox.

However, the answer that meewoK links to probably makes the best point. If it's a text field, you can use your standard keyboard commands (probably the most common way people copy/paste?) or the OS's right-click menu (unless you're overriding it in your app). What Google Docs currently does when you try to access clipboard commands via the Edit menu is display a modal that tells you to use the keyboard commands:

Personally, I would implement something like that while keeping an eye on the Clipboard API. Then, as browsers start to implement it, you can detect its presence and override that modal.

这篇关于添加副本&amp;将功能粘贴到webapp的自定义菜单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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