Webview - change the current page [solved]


Hi :smile:
I am making an application with Electron which uses a <webview>, and I would like change the current page. I looked in the API docs and I found nothing, so I just tried to set the src attribute and it works perfectly :+1: . But when I reload() the webview it takes me back to the initial page, which is annoying. Now I am doing webview.src = webview.getUrl() but it feels more like a workaround than an actual solution. So I would like to know what is the recommended way to change the webview’s current page.
Thanks :smile:


Under the src heading on the page you linked I found:

Writing to this attribute initiates top-level navigation.


Assigning src its own value will reload the current page.

That would seem to be the recommended solution?


You’re completely right, I missed it :sweat_smile:
Thanks for your answer :smile:


I have met an annoying issue that is not exactly what you mention here but is close to that: when you use an AJAX based website, you never leave the initial page and when you try to come back to the initial first screen, it doesn’t work because the webview consider you’re affecting the same URL.

I had to do this to bypass that (tested on version 29.2):

function goHome() {
    var url = require('remote').getGlobal('sharedObject').homeURL;
    if (url != null) {
        if (url.indexOf("?") > -1)
            navigateTo(url + '&' + new Date().getTime());
            navigateTo(url + '?' + new Date().getTime());

The goal is to add a timestamp to the URL to make it different and force the webview to load it instead on staying on the same displayed page.

It’s not very clean so if someone has another idea, I would be happy to know it.