feat: set text/html when copy html text

This commit is contained in:
rcmerci
2021-08-06 15:20:13 +08:00
committed by Tienson Qin
parent 435c2110bc
commit 07917b36c7
3 changed files with 25 additions and 11 deletions

View File

@@ -231,3 +231,22 @@ export const getClipText = function (cb, errorHandler) {
}
})
}
export const writeClipboard = function(text, isHtml) {
if (isHtml) {
var blob = new Blob([text], {type:["text/plain", "text/html"]})
var data = [new ClipboardItem({["text/plain"]: blob, ["text/html"]:blob})];
} else{
var blob = new Blob([text], {type:["text/plain"]})
var data = [new ClipboardItem({["text/plain"]: blob})];
}
navigator.permissions.query({ name: "clipboard-write" }).then((result) => {
if (result.state == "granted" || result.state == "prompt") {
navigator.clipboard.write(data).then(function() {
/* success */
}, function(e) {
console.log(e, "fail")
})
}
})
}