Skip to content

Commit

Permalink
feat: respect base tag's target attribute, closes #7285 (#7344)
Browse files Browse the repository at this point in the history
* feat: respect `base` tag's `target` attribute, closes #7285

* Update core.js

* fix condition
  • Loading branch information
amrbashir committed Jul 11, 2023
1 parent fa7f9b7 commit 757e959
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/core-base-links-target.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:enhance'
---

Open links externally when `<base target="_blank" />` exists
5 changes: 3 additions & 2 deletions core/tauri/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 757e959

Please sign in to comment.