HtmlWindow.WindowFrameElement Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the frame element corresponding to this window.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public HtmlElement WindowFrameElement { get; }

Property Value

Type: System.Windows.Forms.HtmlElement

An HtmlElement corresponding to this window's FRAME element. If this window is not a frame, it returns null.

When you retrieve a FRAME element from the Frames collection, it returns an HtmlWindow. Call WindowFrameElement on this object if you need to access attributes of the underlying FRAME element, such as the SRC attribute.

The following code example compares the SRC attribute of frames in a FRAMESET to the current location. If they are different, the frames are reset to their original URLs.

private void ResetFrames()
      {
	if (!(webBrowser1.Document == null)) 
	{
		HtmlElement frameElement = null;
		HtmlWindow docWindow = webBrowser1.Document.Window;

		foreach (HtmlWindow frameWindow in docWindow.Frames)
		{
			frameElement = frameWindow.WindowFrameElement;
			String originalUrl = frameElement.GetAttribute("SRC");

			if (!originalUrl.Equals(frameWindow.Url.ToString())) 
			{
				frameWindow.Navigate(new Uri(originalUrl));
			}
		}
	}
}

UnauthorizedAccessException

You cannot access a FRAME elements or the FRAME's document if the FRAME is in a different zone than the FRAMESET that contains it. For a full explanation, see About Cross-Frame Scripting and Security.

.NET Framework
Available since 2.0
Return to top
Show: