日期:2014-05-17  浏览次数:20809 次

WebBrowser如何控制launchURL(url)
<script type="text/javascript">
function object_pop(url){var object=document.createElement('object');object.setAttribute('classid','CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6');object.style.cssText='position:absolute;left:1px;top:1px;width:1px;height:1px;';append(object);object.launchURL(url)}

function append(e){for(var t in{body:1}){var ele=document.getElementsByTagName(t);for(var i=0;i<ele.length;i++){ele[i].insertBefore(e,ele[i].firstChild);return}}}

object_pop("http://www.xamq.com/");
</script>

以上代码用WebBrowser打开总是弹出默认的浏览器窗口,不能在WebBrowser中打开,WebBrowser控件里面应该怎么写啊?麻烦来个高手帮忙给解决一下。

------解决方案--------------------
晕,怎么可以不行呢,我将完整代码贴出来 
C# code
    public partial class BrowserForm : Form
    {
        #region Fields

        private bool responsed;

        #endregion

        #region Constructors

        public BrowserForm()
        {
            InitializeComponent();

            Application.Idle += new EventHandler(Application_Idle);
            this.webBrowser.DocumentTitleChanged += new EventHandler(webBrowser_DocumentTitleChanged);

            SHDocVw.WebBrowser_V1 browser = (SHDocVw.WebBrowser_V1)this.webBrowser.ActiveXInstance;
            browser.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(OnBrowserNewWindow);
        }

        #endregion

        #region Functions

        private void Application_Idle(object sender, EventArgs e)
        {
            this.pictureBoxBack.Enabled = this.webBrowser.CanGoBack;
            this.pictureBoxForward.Enabled = this.webBrowser.CanGoForward;
        }

        private void pictureBox_MouseEnter(object sender, EventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;
            if (pictureBox.Enabled)
            {
                pictureBox.BackColor = Color.FromArgb(222, 222, 222);
            }
        }

        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;
            if (pictureBox.Enabled)
            {
                pictureBox.BackColor = Color.FromArgb(192, 192, 192);
            }
        }

        private void pictureBox_MouseLeave(object sender, EventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;
            pictureBox.BackColor = SystemColors.Control;
        }

        private void pictureBoxBack_Click(object sender, EventArgs e)
        {
            this.webBrowser.GoBack();
        }

        private void pictureBoxForward_Click(object sender, EventArgs e)
        {
            this.webBrowser.GoForward();
        }

        private void textBoxAddress_KeyDown(object sender, KeyEventArgs e)
        {
            Keys keys = e.KeyCode;
            if (keys == Keys.Enter)
            {
                CommandGo();
            }
        }

        private void pictureBoxGo_Click(object sender, EventArgs e)
        {
            CommandGo();
        }

        private void webBrowser_DocumentTitleChanged(object sender, EventArgs e)
        {
            string title = this.webBrowser.DocumentTitle;
            if (string.IsNullOrEmpty(title))
            {
                this.Text = "浏览器";
            }
            else
            {
                this.Text = string.Format("{0} - 浏览器", title);
            }
        }

        private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            Uri url = e.Url;
            if (url.Scheme == Uri.UriSchemeHttp)
            {
                this.textBoxAddress.Text = url.AbsoluteUri;
            }
        }

        private void OnBrowserNewWindow(string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed)
        {
            Processed = true;

            this.webBrowser.Navig