閱讀英文

共用方式為


HtmlElementInsertionOrientation 列舉

定義

定義描述使用 InsertAdjacentElement(HtmlElementInsertionOrientation, HtmlElement) 時插入新項目之位置的值。

C#
public enum HtmlElementInsertionOrientation
繼承
HtmlElementInsertionOrientation

欄位

名稱 Description
AfterBegin 1

在目前項目之後插入項目,但要在目前項目中的所有其他內容之前。

AfterEnd 3

在目前項目之後插入項目,但要在目前項目中的所有其他內容之後。

BeforeBegin 0

在目前項目之前插入項目。

BeforeEnd 2

在目前項目之後插入項目。

範例

下列程式碼範例會將 DIV 元素插入使用者檢視 ADatum.com 伺服器外部的每個頁面頂端。 此範例會要求表單包含 WebBrowser 名為 的 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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9