跨浏览器JavaScript粘贴
早些时候,应用程序从window.clipboardData.getData('Text')获取剪贴板的内容。但firefox和chrome不支持这一点跨浏览器JavaScript粘贴,javascript,cross-browser,clipboard,paste,execcommand,Javascript,Cross Browser,Clipboard,Paste,Execcommand,早些时候,应用程序从window.clipboardData.getData('Text')获取剪贴板的内容。但firefox和chrome不支持这一点 function paste() { var input = document.createElement('TEXTAREA'); input.setAttribute('name', 'post'); input.setAttribute('maxlength', 5000); input.setAttri
function paste() {
var input = document.createElement('TEXTAREA');
input.setAttribute('name', 'post');
input.setAttribute('maxlength', 5000);
input.setAttribute('cols',80);
input.setAttribute('rows', 40);
document.body.appendChild (input);
input.contentEditable = true;
input.focus();
if(document.queryCommandEnabled('paste')){
document.execCommand('paste',false,null);
result=input.value;
}
document.body.removeChild(input);
return result;
}
对于复制,调用document.execCommand('copy')将UI内容获取到剪贴板。因为document.execCommand('copy')在firefox和chrome中受支持,所以它在firefox和chrome中工作
而在执行粘贴时,document.execCommand('paste')在firefox中返回false,即使document.queryCommandSupported('paste')为true,document.queryCommandEnabled('paste')在firefox和chrome中返回false,但在IE中返回true。javascript中是否有任何方法使document.execCommand('paste')返回true
单击一个按钮,它会将内容粘贴到UI,在这个应用程序中,表行基本上是从剪贴板数据中追加的。
剪贴簿数据是通过捕获ctrl+c ctrl+v事件捕获的。但我希望访问剪贴板数据、onclick事件或通过document.execCommand(“粘贴”)访问剪贴板数据,后者返回false(在firefox和chrome中)
请给我一个从剪贴板粘贴的解决方案。不幸的是,出于安全原因,您不能使用document.execCommand(“粘贴”)从纯javascript读取剪贴板数据。必须创建web扩展才能执行此操作。不幸的是,出于安全原因,您不能使用document.execCommand(“粘贴”)从纯javascript读取剪贴板数据。您必须创建一个web扩展才能做到这一点。@b如果您使用Chrome,它是真的(它直接使用其本机客户端),如果您使用Firefox,它将不起作用。我还没有测试过它,但谷歌文档似乎正在使用扩展。@b如果您使用Chrome,它是真的(它直接使用其本机客户端),如果你使用Firefox,它将不起作用。我还没有测试过它,但谷歌文档似乎正在使用一个扩展。