简体   繁体   English

document.execCommand(“ paste”)不起作用-返回false

[英]document.execCommand(“paste”) doesn't work - return false

I want to execute the command: 我要执行命令:

document.execCommand("paste");

on Javascript. 关于Javascript。 But it always returns only false! 但是它总是只返回false! The console.log in the example below shows the text "false"! 以下示例中的console.log显示文本“ false”!

 document.querySelector("button").onclick = () => { document.querySelector("input").focus(); console.log("execCommand('paste') returns", document.execCommand("paste")); }; 
 <button>paste</button> <input type="text"> 

Browsers do not generally allow web pages to access the clipboard, as it may contain sensitive information - per MDN docs for execCommand : 浏览器通常不允许网页访问剪贴板,因为它可能包含敏感信息-根据execCommand的MDN文档

paste - Pastes the clipboard contents at the insertion point (replaces current selection). paste -将剪贴板内容粘贴到插入点(替换当前选择)。 Disabled for web content. 禁用网页内容。

An exception to this rule is when the user explicitly pastes data into your web page (via CTRL/Cmd+V or the context menu) - then you can access the clipboard contents in the paste event listener, see https://stackoverflow.com/a/12028136/1026 for details. 此规则的例外情况是,用户将数据明确地粘贴到您的网页中(通过CTRL / Cmd + V或上下文菜单)-然后您可以在paste事件侦听器中访问剪贴板内容,请参阅https://stackoverflow.com / a / 12028136/1026了解详情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 document.execCommand(“ paste”)不执行 - document.execCommand(“paste”) doesn't execute document.execCommand在angularJS中不起作用 - document.execCommand doesn't work in angularJS document.execCommand(&#39;unlink&#39;)不适用于Firefox中的锚点 - document.execCommand('unlink') doesn't work for anchors in Firefox 为什么 document.execCommand(&quot;copy&quot;) 不起作用? - Why document.execCommand("copy") doesn't work? 使 document.execCommand(&#39;insertText&#39;, false, &#39;message&#39;) 与 Draftjs 一起工作? - make document.execCommand('insertText', false, 'message') work with draftjs? document.execCommand(&#39;copy&#39;)在Firefox中不适用于Codemirror textarea字段 - document.execCommand('copy') doesn't work in firefox for codemirror textarea field document.execCommand执行上标和下标在Firefox和Chrome中不起作用 - document.execCommand to execute superscript and subscript doesn't work in Firefox and Chrome 单击div时,为什么document.execCommand不起作用? - Why doesn't the document.execCommand work when I click on a div? document.execCommand粘贴在contentEditable div中不起作用 - document.execCommand paste not working in contentEditable div Safari浏览器不支持document.execCommand(&#39;copy&#39;); 命令? - Safari browser doesn't support document.execCommand('copy'); command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM