【问题标题】:Get Contentwindow of iframe in vba - Access Denied / Permission Denied在 vba 中获取 iframe 的 Contentwindow - 访问被拒绝/权限被拒绝
【发布时间】:2014-06-20 00:17:28
【问题描述】:

我遇到了使用 vba 访问 iframe 的内容窗口的问题。使用 iframe.domain = document.domain 检查时,框架位于同一域中。以下是我到目前为止所尝试的。我阅读了所有网站,但找不到解决方法。任何其他简化同域/跨域消息传递的方法都是非常值得赞赏的。

Dim ie As New InternetExplorer Dim objshell, objshellwindows Dim doc As MSHTML.HTMLDocument Dim doc1 As MSHTML.IHTMLDocument Dim iframe As MSHTML.HTMLIFrame Set objshell = CreateObject("Shell.Application") Set objshellwindows = objshell.Windows For Each ie In objshellwindows If InStr(ie.LocationURL, "http://www.example.com/examples/camera/html/index.html") > 0 Then Set doc = ie.document For Each iframe In doc.getElementsByTagName("IFRAME") Set doc1 = iframe.contentWindow.document '---Access Denied/ Permission Denied Error Next End If Next

【问题讨论】:

    标签: vba excel iframe


    【解决方案1】:

    由于same-origin policy,有时您将无法访问这样的 IFrame。 您可以使用 RegEx 或更好的方法从响应文本中获取数据 - 使用 IFrame 的 src 属性中的链接发送请求并直接获取其内容。

    【讨论】:

      猜你喜欢
      • 2015-07-01
      • 2014-08-10
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多