vba - 在vba中获取iframe的内容窗口 - 访问被拒绝/权限被拒绝

标签 vba excel iframe

我在使用 vba 访问 iframe 的 contentwindow 时遇到问题。使用 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

最佳答案

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

关于vba - 在vba中获取iframe的内容窗口 - 访问被拒绝/权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442949/

相关文章:

ChartSpace 中缺少 Excel VBA "AxisBetweenCategories"属性

sql - 长名称工作表的 ADO 查询导致 Jet 错误

performance - 更快地计算两个位置之间的距离(邮政编码)

excel - VBA:将两列或更多列中的值复制到具有相应行的一列中

excel - 根据顺序删除整行

excel - 如何打开多个工作簿以从中复制数据

c# - 在c#中从excel中获取jpeg格式的图像

css - 始终显示 iframe 垂直滚动条

html - iframe url 内容应使用 jquery 应用 css 样式

javascript - AngularJS 有一个 iFrame,我将信息发送回父级以执行某些操作,但它没有执行