#How to open target="_blank" links on a new window?
10 messages · Page 1 of 1 (latest)
Do you want the new window to be inside of electron? or to open in your browser?
i.e. google chrome
thats a good clarifying question from kashi
Inside of electron.
I'm not sure if it's good practice or not but my guess is probably not. Personally whenever I have a webview running, I whitelist the domains that I would want to allow inside of my electron app, and force all of the other ones to open up inside of chrome
Oh hahaha in that case I would probably enable allow pop-ups
Yep 😄
Do you have some sample code for how you do that? I'm running into an issue with more recent versions of Electron where I can't get links to open in the default browser anymore. I've tried all the easily found solutions through Google
function createMainWindow(){
// Create the browser window.
var mainWindow = new BrowserWindow({
width: 1404,
height: 870,
show:false,
backgroundColor: "#2A303C",
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
// nodeIntegration:true,
contextIsolation:true
},
});
mainWindow.webContents.setWindowOpenHandler((details)=>{shell.openExternal(details.url); return {action:'deny'};});
const temp1 = (isDev) ? mainWindow.webContents.openDevTools() : undefined;
const temp2 = (isDev) ? undefined : mainWindow.removeMenu();
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
return mainWindow;
};
This is what I use to launch my browser window. All links clicked inside open with the user's default browesr