简体   繁体   中英

How can I change BrowserWindow hash url without reloading the page

I'm loading a page in ElectronJS with BrowserWindow.loadURL("http://google.com") . Later on in my application, I need to update the the url by some hash values like http://google.com/#start and I want it to be done without reloading the page as it's the expected behavior.

Using location.assign('#start'); works for me inside a local URL.

You may want to try something like this (untested) from the main process:

let window = new BrowserWindow(/*...*/);
window.loadURL("http://google.com");
//
window.webContents.executeJavaScript("location.assign('#start');");

References:

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