【问题标题】:Electron store reference to new BrowserWindow电子存储对新 BrowserWindow 的引用
【发布时间】:2017-11-16 00:04:05
【问题描述】:

我的应用中有一个 github auth 链接,它触发了“新窗口”侦听器”

mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
// how do i store a reference to the newly created window here
})

如何存储对这个新窗口的引用,以便以后对实例执行操作?

【问题讨论】:

    标签: javascript electron


    【解决方案1】:

    您可以不用让电子制作窗口,而是自己制作窗口,就像文档中进一步说明的那样。

    然后您可以存储对 window 变量的引用并使用它执行以下操作:

    var newWindow;
    
    myBrowserWindow.webContents.on('new-window', (event, url) => {
      event.preventDefault()
      const win = new BrowserWindow({show: false})
      win.once('ready-to-show', () => win.show())
      win.loadURL(url)
      event.newGuest = win
      newWindow      = win;
    })
    
    // Do something with the window.
    newWindow.hide();
    

    Documentation

    【讨论】:

    • 我用这种方法遇到的问题是该链接由firebase SDK触发并打开一个github auth页面。因为链接最初是 about:blank 然后重定向我在调用时无权访问该 url
    • 啊好吧,那你想对窗口做什么?
    • 理想情况下,我想强制链接在用户默认浏览器中的应用程序外部打开,这可能吗?
    • 是的,您可以使用shell.openExternal('www.google.com') 这将在用户默认浏览器中打开 google。 electron.atom.io/docs/api/shell/…
    • 如何在没有访问新窗口监听器中的 url 的情况下执行此操作?
    猜你喜欢
    • 1970-01-01
    • 2017-08-18
    • 2018-06-26
    • 1970-01-01
    • 2018-10-12
    • 2016-06-27
    • 2021-10-22
    • 1970-01-01
    • 2020-12-05
    相关资源
    最近更新 更多