3

I'm making a toolbar on C# for IE and I need to access a certain frame within the website. On my initial tests, I'm just trying to cycle through the frames and have a MessageBox popup with the name of the frame. But I'm encountering an exception whenever I try to do it, saying "Access is denied". The full text of the exception is:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Here's the code:

IHTMLSelectionObject currentSelection = myHTMLDocument.selection;

IHTMLFramesCollection2 frames = (IHTMLFramesCollection2)myHTMLDocument.frames;

for (int i = 0; i < frames.length; i++)
{
    object refIndex = i;

    IHTMLWindow2 currentFrame = (IHTMLWindow2)frames.item(ref refIndex);

    if (currentFrame != null)
    {
        MessageBox.Show(currentFrame.name);
    }
    else
        MessageBox.Show("Null");

}

From my searchs on the web, I found out that this is, in fact, not a bug. It's expected to behave that way. My question is: what is the correct way to do what I'm trying to do?

Thanks in advance!

Josicoco
  • 31
  • 2
  • I've seen this: http://support.microsoft.com/kb/196340 , but I don't know if there is a more complete example in C#. – Josicoco Apr 20 '11 at 22:00

1 Answers1

0

Probably you are getting this message because you are trying to access a frame from another domain. The same origin policy prevent you doing this. To make it work use IServiceProvider.

IServiceProvider isp = (IServiceProvider) currentFrame;

then query using QueryService to get IWebBrowser2 object.

Make sure you use System.Runtime.InteropServices

tangobee
  • 926
  • 7
  • 22