我有以下 HTML
<iframe id ="myIframe">
#document
<head>...</head>
<body>Text I want to get is here</body>
</iframe>
我只知道 iframe 的 id。使用 JavaScript,如何从正文中提取文本?
我有以下 HTML
<iframe id ="myIframe">
#document
<head>...</head>
<body>Text I want to get is here</body>
</iframe>
我只知道 iframe 的 id。使用 JavaScript,如何从正文中提取文本?
假设您的 iframe 与您的 HTML 在同一个域中:
var myIFrame = document.getElementById("myIframe");
var content = myIFrame.contentWindow.document.body.innerHTML;
否则,您将面临一些同源策略问题。