【发布时间】:2021-11-11 07:49:42
【问题描述】:
我有一个简单的
electron.js
应用程序,
electron-quick-start
我在其中使用
<webview>
。
默认情况下,设置了
target=_blank
的链接不会在
webview
内打开。
通过收听在
Can't open Electron webview links with target = blank
给出的
new-window
事件有一些解决方法
但是当
nativeWindowOpen: true
in
webPreferences
在父窗口中时,此解决方法不起作用。当我在
MacOS
上添加
allowpopups
并出现错误
exited with signal SIGSEGV
时,应用程序会崩溃
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
webviewTag: true,
nativeWindowOpen: true // This flag is not letting recieve new-window event from webview
}
})
index.html
是
Hello World!
Hello World!
click on Try it yuorself button in webview
我怎样才能在
target=_blank
工作的地方获得 webview 链接,而
nativeWindowOpen: true
保持在父窗口中?
根据
Planned Breaking API Changes (15.0)
,
nativeWindowOpen
将默认设置为
true
-
不需要在webview标签
webpreferences="nativeWindowOpen=yes" allowpopups
上设置nativeWindowOpen
true吗? -
我尝试添加
webpreferences="nativeWindowOpen=yes"
,但仍然没有接到new-window
事件的调用。添加allowpopups
也会使我的电子应用程序崩溃。 -
为什么
allowpopups
会导致您的应用崩溃?粘贴您用来拦截新窗口的代码?没看到 -
关于 stackoverflow.com/questions/48914542 的进一步请求,我没有时间构建测试代码,但也许您可以在文档 electronjs.org/docs/api/window-open 中查看:“自定义或取消创建窗口,您可以选择在主进程中使用 webContents.setWindowOpenHandler() 设置覆盖处理程序。返回 false 会取消窗口,而返回一个对象会设置创建窗口时使用的 BrowserWindowConstructorOptions ....."
-
@pushkin:我已经添加了
index.html
的代码,或者您也可以尝试在我的代码中设置nativeWindowOpen: true
和allowpopups
,就像在我的index.html
中一样,然后尝试单击具有target=_blank
。在我的 MacOS 上它崩溃了