navigator: added option to not open links in new tab

This commit is contained in:
Leon van Kammen 2024-07-24 12:42:54 +00:00
parent 85a43f07a4
commit bcd94f7bb0
1 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,8 @@
xrf.navigator = {
opts: {
openInNewTab: true
},
URI: xrf.URI.parse(document.location.href)
// scheme: document.location.protocol.replace(/:$/,''),
// directory: document.location.pathname,
@ -134,7 +137,12 @@ xrf.navigator.setupNavigateFallbacks = () => {
if( url.match(/^http/) && url != xrf.navigator.URI.URN && !xrf.loaders[fileExt] ){
let inIframe
try { inIframe = window.self !== window.top; } catch (e) { inIframe = true; }
return inIframe ? window.parent.postMessage({ url }, '*') : window.open( url, '_blank')
if( inIframe ){
window.parent.postMessage({ url }, '*')
}else{
if( xrf.navigator.opts.openInNewTab ) window.open( url, '_blank')
else{ setTimeout( () => document.location.href = url, 1000) }
}
// in case you're running in an iframe, then use this in the parent page:
//
// window.addEventListener("message", (e) => {