本帖最后由 fengjiankun 于 2011-09-14 19:59:28 编辑

解决方案 »

  1.   

    在浏览器Navigated事件中注入一段获取mapObj的值的脚本private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {
        HtmlDocument = this.webBrowser.Document;
        IHTMLDocument2 doc = (IHTMLDocument2)document.DomDocument;
        IHTMLWindow2 window = doc.parentWindow;
        window.execScript("function getMapObj() { return mapObj; }", "javascript");
    }然后在DocumentCompleted事件中去调用这段脚本private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HtmlDocument document = this.webBrowser.Document;
        object mapObj = document.InvokeScript("getMapObj", new object[0]);
    }顺便说一下IHTMLDocument2和IHTMLWindow2接口定义在Microsoft.mshtml.dll中定义,你需要引用这个dll
      

  2.   

    再请教,如何调用mapObj的函数,如下面的函数
    mapObj.setZoomAndCenter(zoom,new MLngLat(lng,lat));//同时设置地图的中心点及zoom级别
      

  3.   

    直接用第一种方式就可以调用了,在DocumentCompleted事件中调用下面的代码private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HtmlDocument = this.webBrowser.Document;
        IHTMLDocument2 doc = (IHTMLDocument2)document.DomDocument;
        IHTMLWindow2 window = doc.parentWindow;
        window.execScript("mapObj.setZoomAndCenter(zoom,new MLngLat(lng,lat));", "javascript");
    }
      

  4.   

    谢谢hustcyb的指教,我是通过动态添加js函数,然后调用函数来实现的。再次感谢!