mirror of https://github.com/layui/layui
优化 `lay.clipboard.writeText`,没有剪贴板写入权限时使用 legacy 方法
parent
e7cb8f9d90
commit
a52f8e0976
|
@ -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…
Reference in New Issue