Merge pull request #138 from nekomeowww/dev/feat-open-in-browser
✨ 支持在默认浏览器中打开 target 为 _blank 的 a 标签外链
This commit is contained in:
10
src-tauri/src/pake.js
vendored
10
src-tauri/src/pake.js
vendored
@@ -306,16 +306,16 @@ window.addEventListener("DOMContentLoaded", (_event) => {
|
|||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest("a");
|
||||||
if (origin && origin.href) {
|
if (origin && origin.href) {
|
||||||
|
const target = origin.target
|
||||||
origin.target = "_self";
|
origin.target = "_self";
|
||||||
|
const hrefUrl = new URL(origin.href)
|
||||||
|
|
||||||
//额外处理下 twitter 的外跳,对于其他需要外跳的可以改这里成对应域名
|
|
||||||
const href = origin.href;
|
|
||||||
if (
|
if (
|
||||||
location.host === "twitter.com" &&
|
window.location.host !== hrefUrl.host && // 如果 a 标签内链接的域名和当前页面的域名不一致 且
|
||||||
href.indexOf("twitter.com") === -1
|
target === '_blank' // a 标签内链接的 target 属性为 _blank 时
|
||||||
) {
|
) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
window.ipc.postMessage(`open_browser:${href}`);
|
window.ipc.postMessage(`open_browser:${origin.href}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user