1

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?

2
  • Can you post the code where you affect the Url in the WebControl and the url you use to test it? Commented May 5, 2014 at 14:02
  • @Askolein i posted in Question Body Commented May 5, 2014 at 14:22

1 Answer 1

4

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

}
Sign up to request clarification or add additional context in comments.

4 Comments

i used this ` if (e.Url.AbsolutePath != webBrowser.Url.AbsolutePath) return;` and it handled
I can see why that works. If however the webBrowser.Url ever gets set to an url that you need to be supressed your code will let it true. Glad it worked out well for you.
rene i used this inside the document complete event. Because your code helped to suppressed "javascript" but on document complete event i watch whenever i-frame loads it fires and different different url were generating.
OK, that scenario didn't spring to mind, I added your option... tnx for the feedback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.