小编Nin*_*ili的帖子

使用iOS中的Javascript复制到剪贴板

我正在使用此功能将URL复制到剪贴板:

function CopyUrl($this){

  var querySelector = $this.next().attr("id");
  var emailLink = document.querySelector("#"+querySelector);

  var range = document.createRange();
  range.selectNode(emailLink);  
  window.getSelection().addRange(range);  

  try {  
    // Now that we've selected the anchor text, execute the copy command  
    var successful = document.execCommand('copy', false, null);
    var msg = successful ? 'successful' : 'unsuccessful'; 

    if(true){
        $this.addClass("copied").html("Copied");
    }

  } catch(err) {  
    console.log('Oops, unable to copy');  
  }  

  // Remove the selections - NOTE: Should use   
  // removeRange(range) when it is supported  
  window.getSelection().removeAllRanges();
}
Run Code Online (Sandbox Code Playgroud)

在桌面浏览器上一切正常,但在我的函数成功返回的iOS设备上没有,但数据根本没有复制到剪贴板.造成这种情况的原因是什么?如何解决这个问题?

javascript clipboard copy mobile-safari ios

67
推荐指数
7
解决办法
6万
查看次数

标签 统计

clipboard ×1

copy ×1

ios ×1

javascript ×1

mobile-safari ×1