【发布时间】:2016-10-07 02:41:16
【问题描述】:
我需要在 nw.js 中捕获 iframe 的内容。该页面位于不同的域中。我尝试正常访问它(myIframe.document),但我得到一个空的 html 文档(可能是某种形式的跨域安全或其他)。但是,我可以从控制台访问 iframe 的内容,我猜我缺少一些设置,可以让我直接从我的代码中执行相同的操作。但是,我不需要 iframe 就可以访问 nw.js(出于安全原因,如果不可能的话会更好)。
<iframe src="http://google.com" width="800" height="600" id="myIframe"></iframe>
<script>
$(function()
{
// Making sure it's actually loaded with help of jquery
$('#myIframe').ready(function () {
console.log(window.frames[0].document);
// Returns:
// <html>
// <head></head>
// <body></body>
// </html>
});
});
</script>
【问题讨论】:
-
我想你会在stackoverflow.com/questions/19627591/… 找到一些帮助——它是关于访问 iframe 和操作它的。稍加调整,我相信它会为你工作。
-
@Ewald 我查看了您的代码,结果发现问题出在我对 jquery 的使用上。当 jquery 的
ready回调被调用时 iframe 并没有真正准备好,但是当onload事件被触发时它已经准备好了。 -
太好了,很高兴您发现了问题,祝您项目顺利。
标签: javascript html iframe nw.js