js 代码由于是原型的
调用无法完成
代码:
我也把 oGthinkrace赋值给 window.tk=oGthinkrace;
后台也调用不了
后台代码:
var ele = webBrowser.Document.GetElementById("map_canvas"); if (ele != null) { object ss = ele.InvokeMember("div.Obj.Locate", new object[] { "abcdee1111" }); }
public static void ExecuteGlobalScript(WebBrowser browser, string script) { if (string.IsNullOrWhiteSpace(script)) return; if (browser.Document == null || browser.Document.Window == null || browser.Document.Window.DomWindow == null) return; try { var win = (IHTMLWindow2)browser.Document.Window.DomWindow; win.execScript(script); } catch (Exception ex) { Debug.Print("{0}\t执行脚本时发生错误:{1}", DateTime.Now, ex.Message); } } public static object ExecuteScript(WebBrowser browser, string script, object[] args = null) { if (string.IsNullOrWhiteSpace(script)) return null; if (browser.Document == null || browser.Document.Window == null || browser.Document.Window.DomWindow == null) return null; var win = (IHTMLWindow2)browser.Document.Window.DomWindow; var scriptName = string.Format("WebBrowserInjectedMethod{0}", Math.Abs(DateTime.Now.ToBinary())); script = string.Format("function {0}(){{{1}}}", scriptName, script); try { win.execScript(script, "javascript"); var result = browser.Document.InvokeScript(scriptName, args); return result; } catch (Exception ex) { Debug.Print("{0}\t执行脚本时发生错误:{1}", DateTime.Now, ex.Message); return null; } }
谢谢 用其他的方式解决了
http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control
谢谢 用其他的方式解决了