【问题标题】:Posting a form to an iframe and get back the content from iframe with javascript?将表单发布到 iframe 并使用 javascript 从 iframe 取回内容?
【发布时间】:2017-07-04 00:30:28
【问题描述】:

我正在开发一个需要从 iframe 获取内容的网站。 代码在这里。

<!DOCTYPE html>
<html>
<head>
    <script src="http://code.jquery.com/jquery-lates…
</head>
<body>
    <iframe src="http://glimmertech.org/IF222.htm" width="80%" height="600" id="frameDemo">       </iframe>

    <script>
    var myFrame = $('#frameDemo');

    myFrame.load(function()
    {
       var myjQueryObject = $('#frameDemo').contents().find('#newid'…
       alert(myjQueryObject[0].innerHTML);
    });
    </script>
</body>
</html>

【问题讨论】:

  • 您无法访问其他域上的 iFrame。如果有办法可以在同一个域上(也许是代理服务器?)那么你可以使用 $.contents()

标签: javascript iframe cross-domain


【解决方案1】:

试试这个:

 var myIframe = document.getElementById('frameDemo');
 var myObject = myIframe.contentWindow.document.getElementById('newid');
 alert(myObject.innerHTML);

【讨论】:

  • 对不起,它不工作,因为 iframe 来自另一个域
猜你喜欢
  • 2015-05-28
  • 2011-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多