将文本从 iframe 拖放到主 window 不会删除文本

drag&drop text from iframe to main window doesn't drop the text

我想将文本从 iframe 拖放到 OSX 上的输入,但它不起作用。

<input />
<iframe
   src="https://react-hooks.org/"
   title="inline browser"
></iframe>
<span>adasdasas</span>

显然这是一个 CORS 问题,请参阅此代码:

<input />
<iframe
   src="https://react-hooks.org/"
   title="inline browser"
></iframe>
<iframe id="myframe"></iframe>

<script>
var ifrm = document.getElementById('myframe');
ifrm = ifrm.contentWindow || ifrm.contentDocument.document || ifrm.contentDocument;
ifrm.document.open();
ifrm.document.write('Hello World!');
ifrm.document.close();
</script>
<span>adasdasas</span>

https://jsfiddle.net/4Lqjvc6p/

在我的测试中,从 #myframe 拖放到 input 时我没有遇到任何困难,因为它使用相同的来源,同时从您的 iframe 执行相同的操作,事实证明,具有不同来源的是不可能的。你可以让你的服务器充当代理来解决这个问题,也就是说,在服务器端请求目标并将内容输出为 iframe 的内容。那应该可以,但是您将难以处理原始文件的 js、css 和 img 内容。