Javascript 邮件后读取Iframe内容
我有一个需求,我需要获取iframe的内容,其中src是另一个域的,下面是我的代码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 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和接收相同结果的步骤是什么结果