Frage

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?

War es hilfreich?

Lösung

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();
    }   

}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top