简体   繁体   English

复制和粘贴在Mobile Safari和CodeMirror上不起作用

[英]Copy&Paste doesn't work on Mobile Safari and CodeMirror

I have wrote the following code: 我写了以下代码:

function copy() {
  if(window.clipboardData) {
    window.clipboardData.clearData();
    window.clipboardData.setData("Text", document.getElementById('txtacpy').value);
  } 
}

function paste() {
  if(window.clipboardData) {   
    document.getElementById('txtapaste').value = window.clipboardData.getData("Text");
  } 
}

When CodeMirror editor is focused I call: 当CodeMirror编辑器聚焦时,我调用:

paste();

But nothing happens! 但没有任何反应! Browser is Mobile Safari. 浏览器是Mobile Safari。 How to fix the issue? 如何解决这个问题?

This functionality is not supported in most browsers because of security issues without allowing a web page to have access to your clipboard. 由于安全问题而不允许网页访问剪贴板,因此大多数浏览器都不支持此功能。 This is not only Mobile Safari. 这不仅仅是Mobile Safari。 You won't find it supported in most browsers (like Chrome or Firefox). 大多数浏览器(如Chrome或Firefox)都不会支持您。

Some people use a Flash work-around called zClip/ZeroClipboard that does allow copying to the clipboard, but only from a direct user click on the Flash object. 有些人使用名为zClip / ZeroClipboard的Flash解决方案 ,它允许复制到剪贴板,但只能直接用户点击Flash对象。 This is obviously not an option in mobile safari. 这显然不是移动野生动物园的选择。

If you are only trying to move data around within your page, then you don't have to use the system clipboard to do that - you can create your own holding area for the data (a javascript variable) and put the data there upon Copy and retrieve it from there upon Paste. 如果您只是想在页面中移动数据,那么您不必使用系统剪贴板来执行此操作 - 您可以为数据创建自己的保留区域(javascript变量)并将数据放在复制中并在粘贴时从那里检索它。 Then, you use normal DOM functions (not copy/paste functions) to get the data from a field or to put the data into a field. 然后,使用普通的DOM函数(不是复制/粘贴函数)从字段中获取数据或将数据放入字段中。

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

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