make sure we dont use history api if user wants to open in a new tab.

This commit is contained in:
Niels Lyngsø
2024-01-11 17:07:43 +01:00
parent f5a6ac0914
commit 68aea19e7b

View File

@@ -3,7 +3,12 @@
* that has a relative HREF, uses the history API instead.
*/
export function ensureAnchorHistory() {
const isWindows = navigator.platform.toUpperCase().indexOf('WIN') !== -1;
window.addEventListener('click', (e: MouseEvent) => {
// If we try to open link in a new tab, then we want to skip skip:
if ((isWindows && e.ctrlKey) || (!isWindows && e.metaKey)) return;
// Find the target by using the composed path to get the element through the shadow boundaries.
const $anchor = (('composedPath' in e) as any)
? e.composedPath().find(($elem) => $elem instanceof HTMLAnchorElement)