当 nativeWindowOpen 在父窗口中为 true 时,electron.j

target=_blank based link in webview in electron.js are not opening when nativeWindowOpen is true in parent window(当 nativeWindowOpen 在父窗口中为 true 时,electron.js 中 webview 中基于 target=_blank 的链接未打开)
本文介绍了当 nativeWindowOpen 在父窗口中为 true 时,electron.js 中 webview 中基于 target=_blank 的链接未打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的 electron.js 应用程序,electron-quick-start 我正在使用 <webview>.

I have simple electron.js application, electron-quick-start in which I am using <webview>.

默认情况下,设置了 target=_blank 的链接不会在 webview 内打开.

By default links in which target=_blank is set does not open inside webview.

通过收听 new 有一些解决方法-window 事件在 不能打开目标 = 空白的 Electron webview 链接

但是当 nativeWindowOpen: true in webPreferences 在父窗口中时,此解决方法不起作用.当我在 MacOS 上添加 allowpopups 并出现错误 exited with signal SIGSEGV

But this workaround does not work when nativeWindowOpen: true in webPreferences in parent window. Rather application get crashed when I am adding allowpopups on MacOS with error 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

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
    <webview id="foo" src="https://www.w3schools.com/tags/att_a_target.asp" style="display:inline-flex; width:640px; height:480px" allowpopups></webview>

    <h1>click on Try it yuorself button in webview</h1>

    <!-- You can also require other files to run in this process -->
    <!-- <script src="./renderer.js"></script> -->
  </body>
</html>

如何在 target=_blank 工作的情况下获取 webview 链接,并在父窗口中保持 nativeWindowOpen: true?

How can I get webview links where target=_blank working keeping nativeWindowOpen: true in parent window?

nativeWindowOpen 将根据 true-changed-nativewindowopen-defaults-to-true" rel="nofollow noreferrer">计划中的重大 API 更改 (15.0)

nativeWindowOpen is going to be set true by default according to Planned Breaking API Changes (15.0)

推荐答案

这是一个错误 https://github.com/electron/electron/pull/29874 已修复.

This was a bug https://github.com/electron/electron/pull/29874 which got fixed.

electron 12.0.14 或更高版本可以很好地解决这个问题.

electron version 12.0.14 or higher is working fine for this problem.

这篇关于当 nativeWindowOpen 在父窗口中为 true 时,electron.js 中 webview 中基于 target=_blank 的链接未打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)