npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-clipboard

v1.3.0

Published

Cordova File Transfer Plugin

Readme

cordova-clipboard

一个为Cordova应用提供系统剪贴板(Clipboard)操作能力的插件,支持Android、iOS和OHOS三平台,可实现文本、HTML及图片的复制与粘贴功能,适配主流移动操作系统剪贴板特性。本文档主要说明在HamronyOS系统中的应用。

概述

在移动应用开发中,剪贴板操作是基础且高频的功能,常用于文本分享、内容复制粘贴(如订单号复制、链接分享、图文复制等)场景。cordova-clipboard插件通过封装原生平台剪贴板API,为开发者提供了统一的跨平台接口,无需深入原生开发即可实现文本、HTML和图片的复制到剪贴板及从剪贴板粘贴操作,同时处理了不同平台剪贴板数据格式的兼容性问题。

支持平台

  • Android:API 19及以上(Android 4.4+)

  • iOS:10.0及以上

  • HarmoyOS:5.0+

安装

通过Cordova CLI或Ionic CLI即可快速安装插件,支持从npm仓库或GitHub仓库获取。

从npm安装(推荐)


# 安装hcordova
npm install -g hcordova

# Cordova CLI
hcordova plugin add cordova-clipboard

从gitCode指定HamronyOS安装


hcordova plugin add https://gitcode.com/OpenHamrony-Cordova/cordova-clipboard.git --platform ohos

安装指定版本


hcordova plugin add [email protected] --platform hamronyos

卸载


# Cordova CLI 全平台卸载
hcordova plugin remove cordova-clipboard 

# 指定平台卸载
hcordova plugin remove cordova-clipboard --platform ohos

核心API

插件在全局对象window.cordova.plugins.clipboard下暴露所有功能接口,支持异步回调和同步调用两种方式(同步调用仅部分API支持)。使用前需确保Cordova设备就绪事件(deviceready)已触发。

1. 复制文本到剪贴板

将指定文本内容复制到系统剪贴板,支持纯文本格式。

方法签名


// 回调方式
window.cordova.plugins.clipboard.copy(text, successCallback, errorCallback)

参数说明

|参数名|类型|说明| |---|---|---| |text|String|必选,需要复制的纯文本内容| |successCallback|Function|可选,成功回调,无参数| |errorCallback|Function|可选,失败回调,参数为错误对象(含message属性)|

2. 从剪贴板粘贴文本

从系统剪贴板中读取文本内容,若剪贴板中为非文本格式则返回空字符串。

方法签名


window.cordova.plugins.clipboard.paste(successCallback, errorCallback)

参数说明

|参数名|类型|说明| |---|---|---| |successCallback|Function|必选,成功回调,参数为剪贴板中的文本内容(String)| |errorCallback|Function|可选,失败回调,参数为错误对象(含message属性)|

6. 清除剪贴板内容

清空系统剪贴板中的所有内容(部分平台可能限制此操作)。

方法签名


window.cordova.plugins.clipboard.clear(successCallback, errorCallback)

参数说明

|参数名|类型|说明| |---|---|---| |successCallback|Function|可选,成功回调,无参数| |errorCallback|Function|可选,失败回调,参数为错误对象(含message属性)|

使用示例

示例1:文本复制粘贴

实现文本框内容复制到剪贴板,以及从剪贴板粘贴到文本框的功能。

//写剪贴版
function clipboardWrite() {
    var text = "Hello World!";
    cordova.plugins.clipboard.copy(text,function(){
        document.getElementById("writeInfo").innerHTML = "写入成功";
    },function() {
        document.getElementById("writeInfo").innerHTML = "写入失败";
    });
}

//读取剪贴版
function clipboardRead() {
    cordova.plugins.clipboard.paste(function (text) {
        document.getElementById("readInfo").innerHTML = "读取内容:"+text;
    },function(error){
        document.getElementById("readInfo").innerHTML = "读取失败:"+error;
    });
}

//清除剪贴板
function  clipboardClear() {
    cordova.plugins.clipboard.clear(function(){
        document.getElementById("clearInfo").innerHTML = "清除成功";
    });
}

许可证

本插件基于 Apache License 开源,详见 LICENSE 文件。

联系方式

OHOS Cordova https://gitcode.com/OpenHarmony-Cordova/cordova-clipboard

Android/iOS:https://npmjs.com/cordova-clipboard/issues