Bewerken

Share via


HtmlWindow.IsClosed Property

Definition

Gets a value indicating whether this window is open or closed.

public:
 property bool IsClosed { bool get(); };
public bool IsClosed { get; }
member this.IsClosed : bool
Public ReadOnly Property IsClosed As Boolean

Property Value

true if the window is still open on the screen; otherwise, false.

Examples

The following code example opens a window, and closes it if the user has not used it in the past five minutes. The code example requires that your form has a WebBrowser control named WebBrowser1, a Button named Button1, and a Timer class named Timer1.

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));
            }
        }
    }
}
Private Sub ResetFrames()
    If (WebBrowser1.Document IsNot Nothing) Then
        Dim FrameElement As HtmlElement
        Dim DocWindow As HtmlWindow = WebBrowser1.Document.Window

        For Each FrameWindow As HtmlWindow In DocWindow.Frames
            FrameElement = FrameWindow.WindowFrameElement
            Dim OriginalUrl As String = FrameElement.GetAttribute("SRC")

            If (Not OriginalUrl.Equals(FrameWindow.Url.ToString())) Then
                FrameWindow.Navigate(New Uri(OriginalUrl))
            End If
        Next
    End If
End Sub

Remarks

If the HtmlWindow has been closed by the user or by way of a call to the Close method, attempting to navigate to a new URL or access the window's document will result in an error. Use this property to determine whether it is safe to call properties and methods on the current window object.

Applies to

See also