Load a new URL in WebView

  1. 5 years ago

    cjp160

    25 Mar 2019 User since 2018

    I can't figure out how to force a WebView to load a new URL. In my settings page, I have two buttons that are suppose to open a window with a WebView that has different URLs loading. If I click the first button, that URL loads properly, but if I click the second button, the URL from the first button is still there and the web page hasn't reloaded.

    Whenever one of these buttons is pressed, I update the URL of the WebView, then when the Window is loading I reload the WebView (thinking that it would reload to its new URL). Is there a way to make this work?

  2. andrea

    26 Mar 2019 Administrator User since 2016

    Hi @cjp160 ,
    you don't need to reload the WebView, it should be enough to set the url property of the WebView to start the loading of the new URL.
    I don't understand if the second time you press a button the second URL is not loaded at all or the second URL is loaded but you initially see the old URL?

  3. marco

    26 Mar 2019 Administrator User since 2016

    Hi @cjp160 to reset the content of a WebView you can use the code:

    WebView1.url = "about:blank";
  4. cjp160

    27 Mar 2019 User since 2018

    @andrea the second time I press a button the second URL is not loaded at all. The WebView doesn't seem to be updating the URL.

    Anytime I set the WebView URL from another window, it gets set to null for some reason. My fix was to expose a property in the WebView Window that is the "newUrl" and then set the WebView URL to that property whenever the WebView Window shows.

  5. andrea

    27 Mar 2019 Administrator User since 2016

    @cjp160, in our tests it seems works correctly, could you please send us a sample project to replicate the issue.
    A possible reason could be the timing of the invocation of the set url and open methods.

or Sign Up to reply!