mirror of https://github.com/layui/layui
优化 `lay.clipboard.writeText`,没有剪贴板写入权限时使用 legacy 方法
parent
e7cb8f9d90
commit
a52f8e0976
|
@ -468,11 +468,16 @@
|
||||||
writeText: function(options) {
|
writeText: function(options) {
|
||||||
var text = String(options.text);
|
var text = String(options.text);
|
||||||
|
|
||||||
try {
|
if(navigator && 'clipboard' in navigator){
|
||||||
navigator.clipboard.writeText(text).then(
|
navigator.clipboard.writeText(text)
|
||||||
options.done
|
.then(options.done, function(){
|
||||||
)['catch'](options.error);
|
legacyCopy();
|
||||||
} catch(e) {
|
});
|
||||||
|
}else{
|
||||||
|
legacyCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
function legacyCopy(){
|
||||||
var elem = document.createElement('textarea');
|
var elem = document.createElement('textarea');
|
||||||
|
|
||||||
elem.value = text;
|
elem.value = text;
|
||||||
|
|
Loading…
Reference in New Issue