Open mask2012 opened 4 years ago
粘贴规律:
必须是点击才能拷贝成功,所以需要一个钩子让用户点击,经过我的试验,普通浏览页面的滑动很难进去
var copyed = false function clipboardWrite(text) { if (copyed) { return } copyed = true var tempDiv = document.createElement("div") tempDiv.id = 'tempDiv'; tempDiv.innerHTML = text; tempDiv.style.position = "absolute"; tempDiv.style.left = "-9999px"; document.body.appendChild(tempDiv); var target = document.getElementById('tempDiv'); var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(target); selection.removeAllRanges(); selection.addRange(range); var a = document.execCommand("Copy", "false", null); selection.removeAllRanges(); console.log('a', a); // mobileConsole(new Date().getTime()) } document.getElementsByTagName("body")[0].addEventListener("click", function () { clipboardWrite('555'); });
粘贴规律:
必须是点击才能拷贝成功,所以需要一个钩子让用户点击,经过我的试验,普通浏览页面的滑动很难进去