HtmlElementInsertionOrientation HtmlElementInsertionOrientation HtmlElementInsertionOrientation HtmlElementInsertionOrientation Enum

定义

定义一些值,这些值描述在使用 InsertAdjacentElement(HtmlElementInsertionOrientation, HtmlElement) 时要插入新元素的位置。Defines values that describe where to insert a new element when using InsertAdjacentElement(HtmlElementInsertionOrientation, HtmlElement).

public enum class HtmlElementInsertionOrientation
public enum HtmlElementInsertionOrientation
type HtmlElementInsertionOrientation = 
Public Enum HtmlElementInsertionOrientation
继承
HtmlElementInsertionOrientationHtmlElementInsertionOrientationHtmlElementInsertionOrientationHtmlElementInsertionOrientation

字段

AfterBegin AfterBegin AfterBegin AfterBegin 1

在当前元素之后、当前元素中其他所有内容之前插入该元素。Insert the element after the current element, but before all other content in the current element.

AfterEnd AfterEnd AfterEnd AfterEnd 3

在当前元素之后、当前元素中其他所有内容之后插入该元素。Insert the element after the current element, but after all other content in the current element.

BeforeBegin BeforeBegin BeforeBegin BeforeBegin 0

在当前元素之前插入该元素。Insert the element before the current element.

BeforeEnd BeforeEnd BeforeEnd BeforeEnd 2

在当前元素之后插入该元素。Insert the element after the current element.

示例

下面的代码示例将一个DIV元素插入到用户在 ADatum.com 服务器外部查看的每一页的顶部。The following code example inserts a DIV element into the top of every page that users view outside of the ADatum.com server. 该示例要求您的窗体包含WebBrowser一个名WebBrowser1为的控件。The example requires that your form contains a WebBrowser control named WebBrowser1. 你的示例还必须导入System.Text.RegularExpressions命名空间。Your example must also import the namespace 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

适用于