From c50ea57c55da4d70c4528842a0e76803de631772 Mon Sep 17 00:00:00 2001 From: Ayaka Neko Date: Fri, 9 Dec 2022 15:13:17 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=94=AF=E6=8C=81=E5=9C=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=B5=8F=E8=A7=88=E5=99=A8=E4=B8=AD=E6=89=93?= =?UTF-8?q?=E5=BC=80=20target=20=E4=B8=BA=20=5Fblank=20=E7=9A=84=20a=20?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=A4=96=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/pake.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/pake.js b/src-tauri/src/pake.js index ee05646..53f5f25 100644 --- a/src-tauri/src/pake.js +++ b/src-tauri/src/pake.js @@ -306,16 +306,16 @@ window.addEventListener("DOMContentLoaded", (_event) => { document.addEventListener("click", (e) => { const origin = e.target.closest("a"); if (origin && origin.href) { + const target = origin.target origin.target = "_self"; + const hrefUrl = new URL(origin.href) - //额外处理下 twitter 的外跳,对于其他需要外跳的可以改这里成对应域名 - const href = origin.href; if ( - location.host === "twitter.com" && - href.indexOf("twitter.com") === -1 + window.location.host !== hrefUrl.host && // 如果 a 标签内链接的域名和当前页面的域名不一致 且 + target === '_blank' // a 标签内链接的 target 属性为 _blank 时 ) { e.preventDefault(); - window.ipc.postMessage(`open_browser:${href}`); + window.ipc.postMessage(`open_browser:${origin.href}`); } } });