Monday 5 June 2017

window.open is not working on electron node.js

I am building cross platform app on electron for my project. I have one js file in which i want to open a link which i am getting it from server and opening in new tab using window.open. Now on electron initial all tasks are getting performed on electron only the window.open function is opening a new tab in default browser not opening new window in electron itself. Here is my main.js of electron for single click open in new window

function(module, exports, __webpack_require__) {


'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _electron = __webpack_require__(14);

function initContextMenu(mainWindow) {
    _electron.ipcMain.on('contextMenuOpened', function (event, targetHref) {
        var contextMenuTemplate = [{
            label: 'Open in new window',
            click: function click() {
                if (targetHref) {
                    new _electron.BrowserWindow().loadURL(targetHref);
                    return;
                }

                mainWindow.useDefaultWindowBehaviour = true;
                mainWindow.webContents.send('contextMenuClosed');
            }
        }];

        var contextMenu = _electron.Menu.buildFromTemplate(contextMenuTemplate);
        contextMenu.popup(mainWindow);
        mainWindow.contextMenuOpen = true;
    });
}

exports.default = initContextMenu;

And the controller.js code where i get the url

var popup;
popup = window.open($scope.machineURL, '_blank');

This works fine on all browsers but not in electron. I want to open my link in new window of electron. Where i am going wrong?



via RAMAN KHARCHE

No comments:

Post a Comment