#How to open target="_blank" links on a new window?

10 messages · Page 1 of 1 (latest)

little depot
#

Is it a good practice to use allowpopups in <webview> to open the target="_blank" links?

lilac fossil
#

Do you want the new window to be inside of electron? or to open in your browser?

#

i.e. google chrome

chilly sparrow
#

thats a good clarifying question from kashi

lilac fossil
#

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

lilac fossil
#

Oh hahaha in that case I would probably enable allow pop-ups

idle gulch
lilac fossil
#
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