webBrowser浏览网址

时间:2011-08-25 22:19:20

标签: c# visual-studio-2010 browser

此代码无效?

private void web_FBCheck_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    if (web_FBCheck.Url.ToString() == ("http://facebook.com/"))
    {
        MessageBox.Show("Welcome to Facebook");
        textBox3.Text = web_FBCheck.Url.ToString();
    }            
}

或在链接

中使用if (web_FBCheck.Url.ToString() == "http://facebook.com/")而不使用( )

1 个答案:

答案 0 :(得分:1)

我猜是因为你正在处理Navigating而不是Navigated,可能是因为网址格式化。你应该做这样的事情:

private void web_FBCheck_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
    if(e.Url.Host.ToLower().IndexOf("facebook.com") > -1) {
        MessageBox.Show("Welcome to Facebook");
        TextBox3.Text = web_FBCheck.Url.ToString();
    }
}