0

I have a C# web page viewer working. What I need to do is when a button is clicked within that webpage, it changes the URL that begins with a certain string, say "xyz". I need to know how I could detect this change. In android I simply used shouldOverrideURlLoading and had an if statement but the only URL I can retrieve is the original one I pass to start the web view. is there a way to call DocumnetedCompleted after each new screen..There are appox. 2 button presses that get me to the screen with the important button

Bnaffy
  • 129
  • 3
  • 14

2 Answers2

0

I think you need something like this

private void change_Url () {
  var URL = Request.Url.ToString(); // get the URL
  // if you meant to appened the text, then
  URL = URL + "abc";
}
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
0

If you are using a WebBrowser control, you can use the Navigating event to handle when the site navigates to another url.

From there you can use the WebBrowserNavigatingEventArgs to retrieve the new URL and to stop it if you want or change the destination URL.

    private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
        if (e.Url.AbsoluteUri.Contains("something")) {
            //stais in the current page
            e.Cancel = true;

            //aditionally you can navigate to another URL (though it will fire this event again)
            webBrowser1.Navigate(e.Url.AbsoluteUri.Replace("something", "empty"));

        } else {
            //continue
        }
    }
Javi
  • 378
  • 2
  • 9
  • I tried it..nothing..maybe I said it wrong.. Within the web page JavaScript is waiting for the button to be pushed and once it is it sends data via json and in android anyways I handled this by looking for a particular URL..I cant seem to do that here..windows 7 c# winform – Bnaffy Jun 17 '14 at 23:01
  • Sorry, that code won't help with ajax calls... the only way I think right now is try to attach a handler to some object and listen when it changes, maybe this could give you an idea: http://stackoverflow.com/questions/635948/c-sharp-webbrowser-control-get-document-elements-after-ajax – Javi Jun 18 '14 at 02:55
  • just an update..in C# winform there is just a webView. No buttons or anything. Within the webpage itself, there are buttons. I need to be able to know when one of these buttons is pressed and do something. In android, shouldOverrideUrlLoading handles just this..does any one know an equivalent for C#???? – Bnaffy Jun 18 '14 at 14:49