Cannot use opener.someScriptVariable in Electron


#1

Hello! I’m new on electron, thanks for providing it.

I implemented a web app and launched with electron.

I want to share some values with opener window and child window.

I tried like this,

//script in opener window

var apiServerInfo = 'http://api.url" ;
var runningChat = function (item) { ... }
....
window.open('/newWindow');

//script in new window
('.drop-wrapper').dropzone({ url : opener.apiServerInfo + '/SSTalk/API/talk/uploadPhoto.do', // just undefined in Electron, but web browsers having value. acceptedFiles : 'image/*', init : function(){ _self = this; this.on('sending', function(file, xhr, formData){ formData.append('photoImage', file); }) this.on('addedfile', function(file){ // alert('file added'); (’.drop-wrapper > .drop’).css(‘display’, ‘none’);
$(’#btn-send’).on(‘click’, function(e){
console.log(_self);
_self.processQueue();
});
})
},
success : function(file, response){
console.log(response);
if(response.result_code === ‘S0000’){
if(opener.runningChat !== ‘empty’){
opener.runningChat.sendImage(response.result.uploaded); // It also undefined in Electron
window.close();
}
}
},

I get the varibles not undefined in Electron, how can I do for this?


#2

To correct window.opener, and work facebook(and others) logins

You need use webPreferences.nativeWindowOpen=true, and set same webPreferences.affinity for mainWindow, and opened windows(hook on mainWindow.webContents.on('new-window'))