[英]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.