private void button1_Click(object sender, EventArgs e) { if (this.webBrowser1.ReadyState == WebBrowserReadyState.Loading || this.webBrowser1.ReadyState == WebBrowserReadyState.Uninitialized) { MessageBox.Show("Please wait for RadEditor to load first."); return; } //Register a script function to extract editor's html string jsFunction = @" function GetEditorHtml() { return RadEditor1.GetHtml(true); }"; IHTMLDocument doc1 = (IHTMLDocument)this.webBrowser1.Document.DomDocument; HTMLWindow2 iHtmlWindow2 = (HTMLWindow2)doc1.Script; //register iHtmlWindow2.execScript(jsFunction, "javascript"); //call the function to get editor's text try { object res = this.webBrowser1.Document.InvokeScript("GetEditorHtml"); MessageBox.Show(res == null ? "null" : res.ToString(), this.Text); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "RadEditor's text: " + this.Text); } }
void SinkScriptErrorEvents() { // Grab the document object off of the Web Browser control IHTMLDocument2 document = (IHTMLDocument2)Browser.Document; if (document == null) { return; } // Grab the window object off of the document object HTMLWindow2 window = (HTMLWindow2)document.parentWindow; if (window == null) { return; } // Cast the window object to the window events interface HTMLWindowEvents2_Event windowEvents = (HTMLWindowEvents2_Event)window; if (windowEvents == null) { return; } // Attach to the error event on the window object; this // will be sent a notification when a script error occurs windowEvents.onerror += Browser_HTMLWindowEvents2_OnError; }
public void Call() { HTMLWindow2 win = (HTMLWindow2)Document.parentWindow; string eventtype = [email protected]; NewEventHandlers(Document.parentWindow.@event); //IHTMLElement activeElement; //switch (eventtype) //{ // case "click": // NewEventHandlers(Document.parentWindow.@event); // activeElement = Document.activeElement; // activeElement.click(); // break; // case "mouseup": // NewEventHandlers(Document.parentWindow.@event); // //OriginalEventHandlers.GetType().InvokeMember("[DispID=0]", System.Reflection.BindingFlags.InvokeMethod, null, OriginalEventHandlers, null); // break; // case "keypress": // NewEventHandlers(Document.parentWindow.@event); // break; // default: // NewEventHandlers(Document.parentWindow.@event); // break; //} }
private static IHTMLElement GetElementById(string elementId) { HTMLDocument document = (HTMLDocument)Browser.Document; for (int i = 0; i < document.frames.length; i++) { object fIndex = i; HTMLWindow2 frame = (HTMLWindow2)document.frames.item(ref fIndex); if (frame.name == "main") { document = (HTMLDocument)frame.document; break; } } IHTMLElement element = document.getElementById(elementId); int nullElementCount = 0; // The following loop is to account for any latency that IE // might experience. Tweak the number of times to attempt // to continue checking the document before giving up. while (element == null && nullElementCount < 2) { Thread.Sleep(500); element = document.getElementById(elementId); nullElementCount++; } return(element); }
public static IHTMLDocument2 GetFrameDocument(HTMLDocument document, int frameIndex) { HTMLWindow2 frame = GetFrame(document, frameIndex); if (frame != null) { return(frame.document); } return(null); }
/// <summary> /// 指定した Window で ScriptExecutor のインスタンスを作成します。 /// </summary> /// <param name="win">script の実行舞台となる window を指定します。</param> public ScriptExecutor(HTMLWindow2 win) //Interop::Marshal. { this.win = win; // execFunc 用の初期化 this.exec("document.body['<mwg:root>']={creatingArrays:[]};"); this._arg = new ExecArguments(this); this.root = new ScriptObject(this, win.document.body.getAttribute("<mwg:root>", 0)); this.root["executor"] = this.FromManaged(this); }
public static void MonitorIE() { IntPtr fgWin = GetForegroundWindow(); //When IE is the active window var fgWinClass = GetWindowClassName(fgWin); if (fgWinClass != "IEFrame" && fgWinClass != "Internet Explorer_TridentDlgFrame") { OnIEActive?.Invoke(false); return; } OnIEActive?.Invoke(true); if (!Scriptlets.Any(o => !o.Disabled)) { return; } IEHtmlDocs.Clear(); var hWnd = desktopHwnd; EnumChildWindows(hWnd, enumIE, ref hWnd); IEHtmlDocs.ToList() .ForEach(o => { var url = o.Item1; var doc = o.Item2; Scriptlets.Where(s => !s.Disabled).ToList().ForEach(s => { try { if (Regex.IsMatch(url, s.UrlMatch)) { doc.body.setAttribute(ChkAttr, "Y"); OnScriptInject?.Invoke(s.UrlMatch); HTMLWindow2 win = (HTMLWindow2)doc.Script; win.execScript(s.Script, "javascript"); DisplayStatus?.Invoke($"Inject [{s.Name}]..."); } } catch (Exception ex) { MessageBox.Show("Script Error: " + ex.Message); } }); }); }