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

pull/1421/head
sight 2023-11-03 06:44:17 +08:00
parent e7cb8f9d90
commit a52f8e0976
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;