Browse Source

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

pull/1421/head
sight 1 year ago
parent
commit
a52f8e0976
  1. 15
      src/modules/lay.js

15
src/modules/lay.js

@ -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;

Loading…
Cancel
Save