Open
Description
您好,我想在单个文件上传之后,将生成的URL路径自动复制到系统剪贴板上,但是尝试了没有效果,想问问解决方法。
我在node/ossstore/lib/upload-job.js
329 行console.log('upload: '+self.from.path+' %celapse','background:green;color:white',self.endTime-self.startTime,'ms')
文件上传完成之后添加了如下代码:
// 拼凑图片URL
var eptpl = self.oss.config.endpoint;
var protocol = eptpl.indexOf('https:') === 0 ? 'https:' : "http:";
var endpoint = eptpl.substr(8); // https://
var link = protocol + '//' + self.to.bucket + '.' + endpoint + '/' + encodeURI(self.to.key);
console.log(link);
// 自动复制到剪贴板
var _self = document.getElementById('copy');
if(_self!==null) {
var parent = _self.parentElement;
if(parent===document.body)
parent.removeChild(_self);
}
var selection = window.getSelection();
var range = document.createRange();
var newDiv = document.createElement("div");
newDiv.id='copy';
newDiv.style.display='none';
document.body.appendChild(newDiv);
newDiv.innerHTML=link;
range.selectNode(document.querySelector('#copy'));
selection.addRange(range);
document.execCommand('copy');
但是没有效果,查资料,可能是chromium的安全策略,自动复制得与用户交互。想问问有没有解决方法。