Interpret network status
var img = new Image(); img.src = 'https://www.baidu.com/favicon.ico?_t=' + Date.now(); img.οnlοad=function(){ if (callback) callback(true) }; img.οnerrοr=function(){ if (callback) callback(false) };
Realize replication (to prevent continuous replication when the network is disconnected)
copybox.oncopy = () => { let routeName = vm.$route.name; if(pageConfig.includes(routeName)){ if(vm.remaminCount<=0){ vm.copy("Please No Copies"); this.$Message.warning("Your copy times for the day have been exhausted"); return false } let selectedStr = window.getSelection().toString(); let copyContent = selectedStr.replace(/\s*/g,''); vm.copy("Please No Copies"); let params ={ activityId: this.$route.params.id, copyContent:copyContent, page:routeName, contentLength:copyContent.length, } try{ vm.addLog(params,selectedStr) }catch (e) { return false } } }
False replication
copy(val) { var oInput = document.createElement('input'); oInput.value = val; document.body.appendChild(oInput); oInput.select(); // select object document.execCommand("Copy"); // execute browser copy command oInput.className = 'oInput'; oInput.style.display='none'; },