当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Copy to clipboard in iOS and Tablet

问题描述:

Im using Backbone and Marionette (javascript frameworks), and i'm trying to implement the next function:

When i click in a button, it will copy one of the inputs of my HTML in the clipboard. I have managed to do it, and it works well in PC, windows phone and s4. But when i try it in tablet (google nexus 10) and in iOS (ipod, ipad...) it doesn't seem to work.

the code is the next

 _onClickCopyName : function(){

var nameToCopy= document.querySelector('.nameAccount'),

range, selection;

selection = window.getSelection();

range = document.createRange();

range.selectNode(nameToCopy);

selection.removeAllRanges();

selection.addRange(range);

document.execCommand('copy');

selection.removeAllRanges();

}

I have debugged it, and it does the same things in pc or the rest of dispositives (even the input i want to copy is selected in all of them) . The difference seams to be the document.execCommand('copy') doesn't work in the tablet or iOS (it works for PC, windows phone and s4).

Do you have any idea why is wrong?

分享给朋友:
您可能感兴趣的文章:
随机阅读: