【问题标题】:How to implement your own SelectAll,Cut,Copy,Paste in Webview如何在 Webview 中实现自己的 SelectAll、Cut、Copy、Paste
【发布时间】:2013-05-30 05:33:51
【问题描述】:

我正在使用 WebView 实现富编辑文本,用于编辑器操作的按钮显示在上下文操作栏 (CAB) 中,在长按 webview 时,它的默认 CAB 显示按钮,我知道 Webview 不提供任何规定自定义它的 CAB。

所以我认为最好实现选择、剪切、复制、粘贴操作。 我已经尝试过this 但对我不起作用。

我的应用程序面向 android 3.x+ 设备。

请建议我如何做到这一点。

【问题讨论】:

    标签: android webview contextual-action-bar richeditabletext


    【解决方案1】:

    我使用BTAndroidWebViewSelection javascript 库来执行此操作。对于剪切、复制和粘贴操作,我注入了自己的 JavaScript。

    • 全选 - (function () { document.execCommand('selectall', true, null);})()
    • 剪切 - (function () { document.execCommand('cut', true, null);})()
    • 复制 - (function () { document.execCommand('copy', true, null);})()
    • 粘贴 - document.execCommand('insertHtml', false,'" + text + "'); 文本是从剪贴板复制的数据。

    谢谢。

    【讨论】:

    • 请注意,由于跨域安全策略,这不适用于您文档中位于不同域的 iframe。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 2021-01-06
    相关资源
    最近更新 更多