Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 邮件后读取Iframe内容_Javascript_Jquery_Iframe_Cross Domain - Fatal编程技术网

Javascript 邮件后读取Iframe内容

Javascript 邮件后读取Iframe内容,javascript,jquery,iframe,cross-domain,Javascript,Jquery,Iframe,Cross Domain,我有一个需求,我需要获取iframe的内容,其中src是另一个域的,下面是我的代码 <iframe id="receiver" src="http://demos.mattwest.io/post-message/receiver.html" width="500" height="200"> <p>Your browser does not support iframes.</p> </iframe> <script> se

我有一个需求,我需要获取iframe的内容,其中src是另一个域的,下面是我的代码

<iframe id="receiver" src="http://demos.mattwest.io/post-message/receiver.html" width="500" height="200">
  <p>Your browser does not support iframes.</p>
</iframe>



<script>
setTimeout(function(){ 
console.log($('#receiver').contents().find('body'));
 }, 2000); 
我搜索了很多,找到了关于PostMessage的信息

在这里,他们正在发送消息,我的目标是获取iframe内容如何在我的场景中实现postMessage

我不能创作小提琴,它显示了一些其他的问题


如何解决这个问题请帮助

iframe上的postMessage
将无法在本地工作。您需要在服务器或以
http
而非
文件开始的测试网站上运行此代码

否则避免jQuery,因为它在
.contents()
中使用postMessage()方法与iFrame通信

纯javascript方式:

使用
.contentDocument

var iframer = document.getElementById('reciever');

var iframeBody = iframer.contentDocument.body;
用例:

iframer.contentDocument.getElementById('someElementInIframe')
等等


希望这有助于
postMessage
iframe本地无法工作。您需要在服务器或以
http
而非
文件开始的测试网站上运行此代码

否则避免jQuery,因为它在
.contents()
中使用postMessage()方法与iFrame通信

纯javascript方式:

使用
.contentDocument

var iframer = document.getElementById('reciever');

var iframeBody = iframer.contentDocument.body;
用例:

iframer.contentDocument.getElementById('someElementInIframe')
等等


希望这有助于

仍然得到相同的错误,我将代码放在wamp www文件夹中。如果我要将代码放在服务器中,实现postmessage和接收相同结果的步骤是什么直到得到相同的错误,我将代码放在wamp www文件夹中。如果我要将代码放在服务器中,实现postmessage和接收相同结果的步骤是什么结果