简体   繁体   中英

how to display full Url in web browser control properly in C#?

I can display the Url in the searchbar. However, it picks up javascript and other loading processes as URL and displays them and doesn't display a conventional Url (eg https://stackoverflow.com/questions ) that we would see in any common browser. So if I search http://www.stackoverflow.com , I get https://ssum-sec.casalemedia.com/usermatch?s=183712&cb=https://engine.adzerk.net/udb/22/sync/i.gif?partnerId=1&userId= . Any help would be appreciated.

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {

            player.SoundLocation = "safepage.wav";
                player.Play();


            if (SearchBar.Text != e.Url.ToString())   //Displays the full Webpage address within the textbox
            {
                SearchBar.Text = e.Url.ToString();
            }

        }

Navigation events of web browser control will raise for iframes of the page too. So in this case, what you are getting as result is address of an iframe in the page.

You can use webBrowser1.Url.ToString() instead of e.Url.ToString() .

Note: As far as I know, there should not be an iframe in stackoverflow questions page, so itt seems your browser has been infected.

In the _Navigated event, you can use the WebBrowser.Url property. It will get updated each time but not for the redirects like for those tracking/ad scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM