feat: respect base tag's target attribute, closes #7285 (#7344)

* feat: respect `base` tag's `target` attribute, closes #7285

* Update core.js

* fix condition
This commit is contained in:
Amr Bashir 2023-07-11 15:11:23 +03:00 committed by GitHub
parent fa7f9b77ab
commit 757e959eb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
'tauri': 'minor:enhance'
---
Open links externally when `<base target="_blank" />` exists

View File

@ -91,13 +91,14 @@
document.querySelector('body').addEventListener( document.querySelector('body').addEventListener(
'click', 'click',
function (e) { function (e) {
var target = e.target let target = e.target
const baseTarget = document.querySelector('head base')?.target
while (target != null) { while (target != null) {
if (target.matches('a')) { if (target.matches('a')) {
if ( if (
target.href && target.href &&
(['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) && (['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) &&
target.target === '_blank' (target.target === '_blank' || (!target.target && baseTarget === "_blank"))
) { ) {
window.__TAURI_INVOKE__('tauri', { window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Shell', __tauriModule: 'Shell',