Note that there are some explanatory texts on larger screens.

plurals
  1. POgetElementById on element within an iframe
    primarykey
    data
    text
    <p>My current code works on elements outside of an iframe. How should I approach fetching elements within an iframe using getElementById? My end goal is to write text within the the <code>&lt;body id="tinymce"&gt;&lt;p&gt;...&lt;/p&gt;&lt;/body&gt;</code> tags. I am not using a webBrowser control - this is for an external instance of iexplore</p> <p><strong>HTML Sample</strong></p> <p><img src="https://i.stack.imgur.com/7P5AU.png" alt="enter image description here"></p> <p><strong>Code Sample</strong></p> <pre><code>foreach (InternetExplorer ie in new ShellWindowsClass()) { if (ie.LocationURL.ToString().IndexOf("intranet_site_url") != -1) { IWebBrowserApp wb = (IWebBrowserApp)ie; while (wb.Busy) { Thread.Sleep(100); } HTMLDocument document = ((HTMLDocument)wb.Document); // FETCH BY ID IHTMLElement element; HTMLInputElementClass hitem; element = document.getElementById("tinymce"); hitem = (HTMLInputElementClass)element; hitem.value = first_name; // FETCH BY ID in IFRAME IHTMLFramesCollection2 hframes = document.frames; for (int i = 0; i &lt; hframes.length; i++) { object ref_index = i; IHTMLWindow2 currentFrame = (IHTMLWindow2)hframes.item(ref ref_index); if (currentFrame != null) { MessageBox.Show(currentFrame.name); // what to do from here? } else MessageBox.Show("Null"); } } } </code></pre> <p><strong>- update idea</strong> Chance of adapting my idea below?</p> <pre><code>if (currentFrame != null) { MessageBox.Show(currentFrame.name); HTMLDocument document_sub = ((HTMLDocument)currentFrame.document); IHTMLElement element_sub; HTMLInputElementClass hitem_sub; element_sub = (document_sub.getElementById("tinymce")); hitem_sub = (HTMLInputElementClass)element_sub; try { hitem_sub.value = first_name; // the above will produce... // InvalidCastException: Unable to cast COM object of type 'mshtml.HTMLBodyCLass' to class type 'mshtml.HTMLInputElementClass' } catch { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload