Selaa lähdekoodia

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

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

* Update core.js

* fix condition
Amr Bashir 2 vuotta sitten
vanhempi
sitoutus
757e959eb2
2 muutettua tiedostoa jossa 8 lisäystä ja 2 poistoa
  1. 5 0
      .changes/core-base-links-target.md
  2. 3 2
      core/tauri/scripts/core.js

+ 5 - 0
.changes/core-base-links-target.md

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

+ 3 - 2
core/tauri/scripts/core.js

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