优化 `lay.clipboard.writeText`,没有剪贴板写入权限时使用 legacy 方法 (#1421)

pull/1422/head
贤心 2023-11-06 09:08:33 +08:00 committed by GitHub
commit 1e7a2d87ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -468,11 +468,16 @@
writeText: function(options) {
var text = String(options.text);
try {
navigator.clipboard.writeText(text).then(
options.done
)['catch'](options.error);
} catch(e) {
if(navigator && 'clipboard' in navigator){
navigator.clipboard.writeText(text)
.then(options.done, function(){
legacyCopy();
});
}else{
legacyCopy();
}
function legacyCopy(){
var elem = document.createElement('textarea');
elem.value = text;