将指定内容写入系统粘贴板,支持同时写入富文本内容与普通文本内容。
目前仅在桌面端生效,html 与 text 其中一个参数必须有值。
insight.clipboard.write(options).then().catch()
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
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>