HtmlElement.InsertAdjacentElement メソッド
アセンブリ: 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
戻り値
挿入された 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); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHtmlElement.InsertAdjacentElement メソッドを検索する場合は、下記のリンクをクリックしてください。

- HtmlElement.InsertAdjacentElement メソッドのページへのリンク