本文介绍了从iframe获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下HTML
<iframe id ="myIframe">
#document
<head>...</head>
<body>Text I want to get is here</body>
</iframe>
我只知道iframe的id。使用JavaScript,如何从正文中提取文本?
I only know the iframe's id. Using JavaScript, how can I extract the text from the body?
推荐答案
假设您的iframe与您的HTML在同一个域中:
Assuming your iframe is in the same domain as your HTML:
var myIFrame = document.getElementById("myIframe");
var content = myIFrame.contentWindow.document.body.innerHTML;
否则你会面对一些问题。
Otherwise you'll face some Same Origin Policy issues.
这篇关于从iframe获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!