How to switch website for a BrowserView without waiting for page reload?2019 Community Moderator ElectionHaving two isolated (in terms of history/cookies/localstorage) BrowserViews in the same BrowserWindow with ElectronHow to force browser to reload cached CSS/JS files?How do I modify the URL without reloading the page?How to auto-reload files in Node.js?Updating address bar with new URL without hash or reloading the pageHow to reload a page using JavaScriptHow can I refresh a page with jQuery?preserving browser “back” button functionality using AJAX/jQuery to load pages and history.pushState() methodHow to make an AJAX call without jQuery?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for itHow can I attach listeners to DOM object when creating an Electron window using the BrowserWindow.loadURL command
How to find the largest number(s) in a list of elements?
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Turning a hard to access nut?
Homology of the fiber
What (if any) is the reason to buy in small local stores?
How do researchers send unsolicited emails asking for feedback on their works?
How to test the sharpness of a knife?
What is the tangent at a sharp point on a curve?
How to remove space in section title at KOMA-Script
PTIJ: Which Dr. Seuss books should one obtain?
Is a square zero matrix positive semidefinite?
How old is Nick Fury?
Why is participating in the European Parliamentary elections used as a threat?
Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?
Friend wants my recommendation but I don't want to
Does convergence of polynomials imply that of its coefficients?
Can "few" be used as a subject? If so, what is the rule?
Should I be concerned about student access to a test bank?
CLI: Get information Ubuntu releases
Unfrosted light bulb
UK Tourist Visa- Enquiry
Do I need to convey a moral for each of my blog post?
What is it called when someone votes for an option that's not their first choice?
What will the Frenchman say?
How to switch website for a BrowserView without waiting for page reload?
2019 Community Moderator ElectionHaving two isolated (in terms of history/cookies/localstorage) BrowserViews in the same BrowserWindow with ElectronHow to force browser to reload cached CSS/JS files?How do I modify the URL without reloading the page?How to auto-reload files in Node.js?Updating address bar with new URL without hash or reloading the pageHow to reload a page using JavaScriptHow can I refresh a page with jQuery?preserving browser “back” button functionality using AJAX/jQuery to load pages and history.pushState() methodHow to make an AJAX call without jQuery?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for itHow can I attach listeners to DOM object when creating an Electron window using the BrowserWindow.loadURL command
Let's say I have a BrowserView inside a BrowserWindow:
browserWindow = new BrowserWindow( width: 1200, height: 600 );
browserWindow.webContents.loadURL('file://' + __dirname + '/top_toolbar.html');
let browserView1 = new BrowserView( webPreferences: nodeIntegration: false );
browserWindow.setBrowserView(browserView1);
browserView1.setBounds( x: 0, y: 50, width: 600, height: 600 ); // y=50 to keep top toolbar
browserView1.webContents.loadURL('https://www.twitter.com');
When I click on a UI button (another "tab", like in a browser), I'd like to change the URL to another website (such as https://www.gmail.com).
When I'll click back to the first "tab", I'd like that the BrowserView recovers the previous website (Twitter) and all its browsing history. Obviously, using:
browserView1.webContents.loadURL('https://www.twitter.com');
again wouldn't be a good solution because there would be a page loading waiting time.
Instead I'd like to restore the previous state of the BrowserView instantly (i.e. < 50 ms), exactly like when you click on a tab in a browser like Chrome or Firefox: if the website in the tab has already been loaded before, clicking on the tab just re-displays it.
Question: how to store and then restore instantly a BrowserView state? i.e. without requiring to reload the page?

javascript
add a comment |
Let's say I have a BrowserView inside a BrowserWindow:
browserWindow = new BrowserWindow( width: 1200, height: 600 );
browserWindow.webContents.loadURL('file://' + __dirname + '/top_toolbar.html');
let browserView1 = new BrowserView( webPreferences: nodeIntegration: false );
browserWindow.setBrowserView(browserView1);
browserView1.setBounds( x: 0, y: 50, width: 600, height: 600 ); // y=50 to keep top toolbar
browserView1.webContents.loadURL('https://www.twitter.com');
When I click on a UI button (another "tab", like in a browser), I'd like to change the URL to another website (such as https://www.gmail.com).
When I'll click back to the first "tab", I'd like that the BrowserView recovers the previous website (Twitter) and all its browsing history. Obviously, using:
browserView1.webContents.loadURL('https://www.twitter.com');
again wouldn't be a good solution because there would be a page loading waiting time.
Instead I'd like to restore the previous state of the BrowserView instantly (i.e. < 50 ms), exactly like when you click on a tab in a browser like Chrome or Firefox: if the website in the tab has already been loaded before, clicking on the tab just re-displays it.
Question: how to store and then restore instantly a BrowserView state? i.e. without requiring to reload the page?

javascript
Use multiple BrowserViews, and show/hide them.
– Chris G
Mar 6 at 23:21
@ChrisG: Electron 4 can't have multiple BrowserViews AFAIK, it requires Electron 5 (still beta), is that right?
– Basj
Mar 6 at 23:27
you can have multiple instance of browserview, only can't display them at once, You can attach / detach desired instance when you need to display specific one.
– OJ Kwon
Mar 7 at 0:30
@Basj I haven't tested it, but I imagine something like this:var bw1 = new BrowserView(...); var bw2 = new BrowserView(...);ThenbrowserWindow.setBrowserView(bw1);to show the first, andbrowserWindow.setBrowserView(bw2);to show the second?
– Chris G
Mar 7 at 15:26
add a comment |
Let's say I have a BrowserView inside a BrowserWindow:
browserWindow = new BrowserWindow( width: 1200, height: 600 );
browserWindow.webContents.loadURL('file://' + __dirname + '/top_toolbar.html');
let browserView1 = new BrowserView( webPreferences: nodeIntegration: false );
browserWindow.setBrowserView(browserView1);
browserView1.setBounds( x: 0, y: 50, width: 600, height: 600 ); // y=50 to keep top toolbar
browserView1.webContents.loadURL('https://www.twitter.com');
When I click on a UI button (another "tab", like in a browser), I'd like to change the URL to another website (such as https://www.gmail.com).
When I'll click back to the first "tab", I'd like that the BrowserView recovers the previous website (Twitter) and all its browsing history. Obviously, using:
browserView1.webContents.loadURL('https://www.twitter.com');
again wouldn't be a good solution because there would be a page loading waiting time.
Instead I'd like to restore the previous state of the BrowserView instantly (i.e. < 50 ms), exactly like when you click on a tab in a browser like Chrome or Firefox: if the website in the tab has already been loaded before, clicking on the tab just re-displays it.
Question: how to store and then restore instantly a BrowserView state? i.e. without requiring to reload the page?

javascript
Let's say I have a BrowserView inside a BrowserWindow:
browserWindow = new BrowserWindow( width: 1200, height: 600 );
browserWindow.webContents.loadURL('file://' + __dirname + '/top_toolbar.html');
let browserView1 = new BrowserView( webPreferences: nodeIntegration: false );
browserWindow.setBrowserView(browserView1);
browserView1.setBounds( x: 0, y: 50, width: 600, height: 600 ); // y=50 to keep top toolbar
browserView1.webContents.loadURL('https://www.twitter.com');
When I click on a UI button (another "tab", like in a browser), I'd like to change the URL to another website (such as https://www.gmail.com).
When I'll click back to the first "tab", I'd like that the BrowserView recovers the previous website (Twitter) and all its browsing history. Obviously, using:
browserView1.webContents.loadURL('https://www.twitter.com');
again wouldn't be a good solution because there would be a page loading waiting time.
Instead I'd like to restore the previous state of the BrowserView instantly (i.e. < 50 ms), exactly like when you click on a tab in a browser like Chrome or Firefox: if the website in the tab has already been loaded before, clicking on the tab just re-displays it.
Question: how to store and then restore instantly a BrowserView state? i.e. without requiring to reload the page?

javascript
javascript
edited Mar 6 at 23:20
Basj
asked Mar 6 at 23:15
BasjBasj
6,10832107241
6,10832107241
Use multiple BrowserViews, and show/hide them.
– Chris G
Mar 6 at 23:21
@ChrisG: Electron 4 can't have multiple BrowserViews AFAIK, it requires Electron 5 (still beta), is that right?
– Basj
Mar 6 at 23:27
you can have multiple instance of browserview, only can't display them at once, You can attach / detach desired instance when you need to display specific one.
– OJ Kwon
Mar 7 at 0:30
@Basj I haven't tested it, but I imagine something like this:var bw1 = new BrowserView(...); var bw2 = new BrowserView(...);ThenbrowserWindow.setBrowserView(bw1);to show the first, andbrowserWindow.setBrowserView(bw2);to show the second?
– Chris G
Mar 7 at 15:26
add a comment |
Use multiple BrowserViews, and show/hide them.
– Chris G
Mar 6 at 23:21
@ChrisG: Electron 4 can't have multiple BrowserViews AFAIK, it requires Electron 5 (still beta), is that right?
– Basj
Mar 6 at 23:27
you can have multiple instance of browserview, only can't display them at once, You can attach / detach desired instance when you need to display specific one.
– OJ Kwon
Mar 7 at 0:30
@Basj I haven't tested it, but I imagine something like this:var bw1 = new BrowserView(...); var bw2 = new BrowserView(...);ThenbrowserWindow.setBrowserView(bw1);to show the first, andbrowserWindow.setBrowserView(bw2);to show the second?
– Chris G
Mar 7 at 15:26
Use multiple BrowserViews, and show/hide them.
– Chris G
Mar 6 at 23:21
Use multiple BrowserViews, and show/hide them.
– Chris G
Mar 6 at 23:21
@ChrisG: Electron 4 can't have multiple BrowserViews AFAIK, it requires Electron 5 (still beta), is that right?
– Basj
Mar 6 at 23:27
@ChrisG: Electron 4 can't have multiple BrowserViews AFAIK, it requires Electron 5 (still beta), is that right?
– Basj
Mar 6 at 23:27
you can have multiple instance of browserview, only can't display them at once, You can attach / detach desired instance when you need to display specific one.
– OJ Kwon
Mar 7 at 0:30
you can have multiple instance of browserview, only can't display them at once, You can attach / detach desired instance when you need to display specific one.
– OJ Kwon
Mar 7 at 0:30
@Basj I haven't tested it, but I imagine something like this:
var bw1 = new BrowserView(...); var bw2 = new BrowserView(...); Then browserWindow.setBrowserView(bw1); to show the first, and browserWindow.setBrowserView(bw2); to show the second?– Chris G
Mar 7 at 15:26
@Basj I haven't tested it, but I imagine something like this:
var bw1 = new BrowserView(...); var bw2 = new BrowserView(...); Then browserWindow.setBrowserView(bw1); to show the first, and browserWindow.setBrowserView(bw2); to show the second?– Chris G
Mar 7 at 15:26
add a comment |
2 Answers
2
active
oldest
votes
The solution is to have multiple BrowserViews and switch between them. That way each will remember its history.
var browserViews = [];
var activeBW;
function addAndSwitchToTab()
activeBW = browserViews.length;
browserViews[activeBW] = new BrowserView();
browserWindow.setBrowserView(activeBW);
Start with the first one:
addAndSwitchToTab();
When the user opens a new tab, just call the function again.
1
Thank you very much @ChrisG! Here is a linked question (how to have the differentBrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908
– Basj
Mar 8 at 12:42
add a comment |
Try this for button click:
onClick()
const shell = require('electron').shell;
event.preventDefault();
shell.openExternal('https://www.twitter.com');
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033691%2fhow-to-switch-website-for-a-browserview-without-waiting-for-page-reload%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The solution is to have multiple BrowserViews and switch between them. That way each will remember its history.
var browserViews = [];
var activeBW;
function addAndSwitchToTab()
activeBW = browserViews.length;
browserViews[activeBW] = new BrowserView();
browserWindow.setBrowserView(activeBW);
Start with the first one:
addAndSwitchToTab();
When the user opens a new tab, just call the function again.
1
Thank you very much @ChrisG! Here is a linked question (how to have the differentBrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908
– Basj
Mar 8 at 12:42
add a comment |
The solution is to have multiple BrowserViews and switch between them. That way each will remember its history.
var browserViews = [];
var activeBW;
function addAndSwitchToTab()
activeBW = browserViews.length;
browserViews[activeBW] = new BrowserView();
browserWindow.setBrowserView(activeBW);
Start with the first one:
addAndSwitchToTab();
When the user opens a new tab, just call the function again.
1
Thank you very much @ChrisG! Here is a linked question (how to have the differentBrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908
– Basj
Mar 8 at 12:42
add a comment |
The solution is to have multiple BrowserViews and switch between them. That way each will remember its history.
var browserViews = [];
var activeBW;
function addAndSwitchToTab()
activeBW = browserViews.length;
browserViews[activeBW] = new BrowserView();
browserWindow.setBrowserView(activeBW);
Start with the first one:
addAndSwitchToTab();
When the user opens a new tab, just call the function again.
The solution is to have multiple BrowserViews and switch between them. That way each will remember its history.
var browserViews = [];
var activeBW;
function addAndSwitchToTab()
activeBW = browserViews.length;
browserViews[activeBW] = new BrowserView();
browserWindow.setBrowserView(activeBW);
Start with the first one:
addAndSwitchToTab();
When the user opens a new tab, just call the function again.
answered Mar 8 at 11:26
Chris GChris G
6,40321022
6,40321022
1
Thank you very much @ChrisG! Here is a linked question (how to have the differentBrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908
– Basj
Mar 8 at 12:42
add a comment |
1
Thank you very much @ChrisG! Here is a linked question (how to have the differentBrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908
– Basj
Mar 8 at 12:42
1
1
Thank you very much @ChrisG! Here is a linked question (how to have the different
BrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908– Basj
Mar 8 at 12:42
Thank you very much @ChrisG! Here is a linked question (how to have the different
BrowserViews "isolated" in terms of cookies/accounts connected), in case you have an idea: stackoverflow.com/q/55061908– Basj
Mar 8 at 12:42
add a comment |
Try this for button click:
onClick()
const shell = require('electron').shell;
event.preventDefault();
shell.openExternal('https://www.twitter.com');
add a comment |
Try this for button click:
onClick()
const shell = require('electron').shell;
event.preventDefault();
shell.openExternal('https://www.twitter.com');
add a comment |
Try this for button click:
onClick()
const shell = require('electron').shell;
event.preventDefault();
shell.openExternal('https://www.twitter.com');
Try this for button click:
onClick()
const shell = require('electron').shell;
event.preventDefault();
shell.openExternal('https://www.twitter.com');
edited Mar 7 at 23:37
Cody Gray♦
194k35382469
194k35382469
answered Mar 7 at 5:17
Atchutha rama reddy KarriAtchutha rama reddy Karri
214
214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033691%2fhow-to-switch-website-for-a-browserview-without-waiting-for-page-reload%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use multiple BrowserViews, and show/hide them.
– Chris G
Mar 6 at 23:21
@ChrisG: Electron 4 can't have multiple BrowserViews AFAIK, it requires Electron 5 (still beta), is that right?
– Basj
Mar 6 at 23:27
you can have multiple instance of browserview, only can't display them at once, You can attach / detach desired instance when you need to display specific one.
– OJ Kwon
Mar 7 at 0:30
@Basj I haven't tested it, but I imagine something like this:
var bw1 = new BrowserView(...); var bw2 = new BrowserView(...);ThenbrowserWindow.setBrowserView(bw1);to show the first, andbrowserWindow.setBrowserView(bw2);to show the second?– Chris G
Mar 7 at 15:26