HtmlElementInsertionOrientation 枚举

定义

定义一些值,这些值描述在使用 InsertAdjacentElement(HtmlElementInsertionOrientation, HtmlElement) 时要插入新元素的位置。

C#
public enum HtmlElementInsertionOrientation
继承
HtmlElementInsertionOrientation

字段

AfterBegin 1

在当前元素之后、当前元素中其他所有内容之前插入该元素。

AfterEnd 3

在当前元素之后、当前元素中其他所有内容之后插入该元素。

BeforeBegin 0

在当前元素之前插入该元素。

BeforeEnd 2

在当前元素之后插入该元素。

示例

下面的代码示例将元素 DIV 插入到用户查看 ADatum.com 服务器外部的每个页面顶部。 The example requires that your form contains a WebBrowser control named WebBrowser1. 示例还必须导入命名空间 System.Text.RegularExpressions

C#
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);
    }
}

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7