用AxWebbrowser做的浏览器
怎么通过javascript掉用winform中的方法?
如果是webbrowser的话,可以在WINFORM中声明
using System.Web.UI.WebControls.WebParts;
using System.Runtime.InteropServices;namespace WindowsApplication4
{
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.ObjectForScripting = this;                       
        }
        //JS中调用的方法:
        public void addTab(string str) 
        {
            MessageBox.Show(str);
        }
    }
}
在JS中可以:external.addTab(obj.value)
那么请问:AxWebBrowser中怎么实现

解决方案 »

  1.   

    好像IE7也用不了下面的方法,但你可以考虑别的类似的方法        //JS中调用的方法:
            public void addTab(string str)
            {
                MessageBox.Show(str);
            }         private void Form1_Load(object sender, EventArgs e)
            {          
                axWebBrowser1.Navigate("c:\\1.html");
            }        private void axWebBrowser1_StatusTextChange(object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
            {
                if (e.text == "value")
                {
                    addTab(e.text);
                }
            }
    JS:
    <script type="text/javascript">
    window.status="value";
    </script>
      

  2.   

    感谢ZengHD,传status局限性太大了,不过挺有启发的,再研究一下