简体   繁体   English

window.document.execCommand()无法正常工作

[英]window.document.execCommand() is not working

I am trying to copy a string into clipboard using a dummy input element in my angularjs application. 我正在尝试使用我的angularjs应用程序中的虚拟输入元素将字符串复制到剪贴板中。 The following broadcast handler is called, and the input.value is set to the right value. 调用以下广播处理程序,并将input.value设置为正确的值。 However window.document.execCommand() has no effect. 但是window.document.execCommand()无效。

$scope.$root.$on('on-share-link-made', function (event, args) {
    var input = $('#MyInput')[0];
    input.value = args.uri;
    input.select();
    window.document.execCommand("copy");
});

I need to see your html and possibly your css. 我需要查看您的HTML以及可能的CSS。 execCommand wont work if the input has display: none , width: 0 or height: 0 . 如果输入display: none ,则execCommand不起作用display: none输入, width: 0height: 0 If you are trying to copy some string in the ui, your best approach is to position the input tag using absolute/fixed position out of vision. 如果要在ui中复制某些字符串,则最好的方法是使用视力范围之外的绝对/固定位置来定位输入标签。

仅当在事件处理程序(如按钮单击)中调用window.document.execCommand时,该命令才起作用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM