写入剪贴板

将指定内容写入系统粘贴板,支持同时写入富文本内容与普通文本内容。

目前仅在桌面端生效,html 与 text 其中一个参数必须有值。

insight.clipboard.write(options).then().catch()

options 参数说明

名称 类型 必填 描述
html String 富文本内容,需要使用encodeURIComponent编码
text String 普通文本内容,需要使用encodeURIComponent编码

代码示例

<button id="write">write</button>
<script>
    document.getElementById("write").addEventListener('click', function(e) {
        var html = encodeURIComponent(`<a href="https://github.com">electron</a>`)
        var text = encodeURIComponent('Github https://github.com')
        insight.clipboard.write(html, text)
            .then(data => {
                alert(JSON.stringify(data));
            })
            .catch(error => {
                alert(JSON.stringify(error));
            })
    }, false);
</script>