5
votes

I am stuck in an issue accessing contentwindow of iframe using vba. The frames are in same domain when check using iframe.domain = document.domain. Below is what I have tried so far. I read all websites but couldn't find a way to get a workaround. Any other method for simplifying same domain/ cross domain messaging is highly appreciable.


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

1

1 Answers

0
votes

Sometimes you won't be able to access an IFrame like this due to same-origin policy. You can either get data from response text with RegEx or better - use a link from src attribute of your IFrame to send a request and get its contents directly.