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" });
}
2 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
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; } }
- 2 回答
- 0 关注
- 366 浏览
添加回答
举报
0/150
提交
取消