다음을 통해 공유


HtmlElementInsertionOrientation 열거형

정의

InsertAdjacentElement(HtmlElementInsertionOrientation, HtmlElement)를 사용할 때 새 요소를 넣을 위치를 설명하는 값을 정의합니다.

public enum class HtmlElementInsertionOrientation
public enum HtmlElementInsertionOrientation
type HtmlElementInsertionOrientation = 
Public Enum HtmlElementInsertionOrientation
상속
HtmlElementInsertionOrientation

필드

AfterBegin 1

현재 요소 뒤, 현재 요소의 다른 모든 콘텐츠 앞에 요소를 삽입합니다.

AfterEnd 3

현재 요소 뒤, 현재 요소의 다른 모든 콘텐츠 뒤에 요소를 삽입합니다.

BeforeBegin 0

현재 요소 앞에 요소를 삽입합니다.

BeforeEnd 2

현재 요소 뒤에 요소를 삽입합니다.

예제

다음 코드 예제에서는 삽입을 DIV ADatum.com 서버 외부에서 볼 수 있는 모든 페이지의 맨 위에 있는 요소입니다. 폼이 예제는 WebBrowser 라는 컨트롤 WebBrowser1합니다. 예제의 네임 스페이스를 가져와야도 System.Text.RegularExpressions합니다.

public void AddDivMessage()
{
    Uri currentUri = new Uri(webBrowser1.Url.ToString());
    String hostName = null;

    // Ensure we have a host name, and not just an IP, against which to test.
    if (!(currentUri.HostNameType == UriHostNameType.Dns))
    {
        DnsPermission permit = new DnsPermission(System.Security.Permissions.PermissionState.Unrestricted);
        permit.Assert();

        IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(currentUri.Host);
        hostName = hostEntry.HostName;
    }
    else
    {
        hostName = currentUri.Host;
    }

    if (!hostName.Contains("adatum.com"))
    {
        AddTopPageMessage("You are viewing a web site other than ADatum.com. " +
            "Please exercise caution, and ensure your Web surfing complies with all " +
            "corporate regulations as laid out in the company handbook.");
    }
}

private void AddTopPageMessage(String message)
{
    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;

        // Do not insert the warning again if it already exists. 
        HtmlElementCollection returnedElems = doc.All.GetElementsByName("ADatumWarningDiv");
        if ((returnedElems != null) && (returnedElems.Count > 0))
        {
            return;
        }

        HtmlElement divElem = doc.CreateElement("DIV");
        divElem.Name = "ADatumWarningDiv";
        divElem.Style = "background-color:black;color:white;font-weight:bold;width:100%;";
        divElem.InnerText = message;

        divElem = doc.Body.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterBegin, divElem);
    }
}
Private Sub AddDivMessage()
    Dim CurrentUri As New Uri(WebBrowser1.Url.ToString())
    Dim HostName As String

    ' Ensure we have a host name, and not just an IP, against which to test.
    If (Not CurrentUri.HostNameType = UriHostNameType.Dns) Then
        Dim Permit As New DnsPermission(System.Security.Permissions.PermissionState.Unrestricted)
        Permit.Assert()

        Dim HostEntry As IPHostEntry = System.Net.Dns.GetHostEntry(CurrentUri.Host)
        HostName = HostEntry.HostName
    Else
        HostName = CurrentUri.Host
    End If

    If (Not HostName.Contains("adatum.com")) Then
        AddTopPageMessage("You are viewing a web site other than ADatum.com. " & _
            "Please exercise caution, and ensure your web surfing complies with all " & _
            "corporate regulations as laid out in the company handbook.")
    End If
End Sub

Private Sub AddTopPageMessage(ByVal Message As String)
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            ' Do not insert the warning again if it already exists. 
            Dim ReturnedElems As HtmlElementCollection = .All.GetElementsByName("ADatumWarningDiv")
            If (Not (ReturnedElems Is Nothing) And (ReturnedElems.Count > 0)) Then
                Exit Sub
            End If

            Dim DivElem As HtmlElement = .CreateElement("DIV")
            DivElem.Name = "ADatumWarningDiv"
            DivElem.Style = "background-color:black;color:white;font-weight:bold;width:100%;"
            DivElem.InnerText = Message

            DivElem = .Body.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterBegin, DivElem)
        End With
    End If
End Sub

적용 대상