HtmlElement.InsertAdjacentElement メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HtmlElement.InsertAdjacentElement メソッドの意味・解説 

HtmlElement.InsertAdjacentElement メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

新し要素を DOM に挿入します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Function InsertAdjacentElement ( _
    orient As HtmlElementInsertionOrientation, _
    newElement As HtmlElement _
) As HtmlElement
Dim instance As HtmlElement
Dim orient As HtmlElementInsertionOrientation
Dim newElement As HtmlElement
Dim returnValue As HtmlElement

returnValue = instance.InsertAdjacentElement(orient, newElement)
public HtmlElement InsertAdjacentElement (
    HtmlElementInsertionOrientation orient,
    HtmlElement newElement
)
public:
HtmlElement^ InsertAdjacentElement (
    HtmlElementInsertionOrientation orient, 
    HtmlElement^ newElement
)
public HtmlElement InsertAdjacentElement (
    HtmlElementInsertionOrientation orient, 
    HtmlElement newElement
)
public function InsertAdjacentElement (
    orient : HtmlElementInsertionOrientation, 
    newElement : HtmlElement
) : HtmlElement

パラメータ

orient

現在の要素基準とした、この要素挿入位置

newElement

挿入する新し要素

戻り値
挿入されHtmlElement挿入失敗した場合null 参照 (Visual Basic では Nothing) を返します

解説解説

このメソッドは、WebBrowser コントロールの DocumentCompleted イベント発生するまで呼び出さないください。その前にこのメソッド呼び出すと、ドキュメント読み込み終了していないため、例外スローさます。

HtmlElementInsertionOrientation の値が有効であるかどうかは、要素種類によって異なります。たとえば、AfterBegin は DIV 要素については有効ですが、SCRIPT 要素IMG 要素については有効ではありません。これは、これらの要素どちらも子要素を持つことができないからです。

使用例使用例

次のコード例では、ユーザーが ADatum.com サーバー以外から表示するすべてのページ最上部に、DIV 要素挿入します。この例では、フォームWebBrowser1 という名前の WebBrowser コントロール含まれている必要がありますまた、名前空間 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);
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHtmlElement.InsertAdjacentElement メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHtmlElement.InsertAdjacentElement メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHtmlElement.InsertAdjacentElement メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HtmlElement.InsertAdjacentElement メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlElement.InsertAdjacentElement メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS