문제

I am using a web browser control in a window form. Whenever I open a web site in my web browser control it sometimes shows an absolute URL ( e.g. https://employer.dice.com/daf/servlet/DAFctrl) and then suddenly it changes to javascript:false;.

When I use a regular web browser to open the same link then it does not change the URL to javascript:false;.

private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
        tbUrl.Text = e.Url.ToString();

    }

Any idea how to resolve this kind of issue?

도움이 되었습니까?

해결책

It is up to you how to handle navigation events. Browsers probably supress navigation events that doesn't change the current resource. You could do the same:

private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    WebBrowser browser = sender as WebBrowser;
    // only change the url if the Scheme is not javascript
    if (!e.Url.Scheme.StartsWith(
                       "javascript",  
                       StringComparison.CurrentCultureIgnoreCase)
        && ( browser !=null && (e.Url.AbsolutePath == browser.Url.AbsolutePath)) )
    {
        tbUrl.Text = e.Url.ToString();
    }   

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top