From f32a72210c81c138ecf86accbffc1d9d86799164 Mon Sep 17 00:00:00 2001 From: xan2622 Date: Thu, 12 Nov 2026 20:09:33 +0100 Subject: [PATCH] Fix Back button not returning to the parent folder The Back link used href="#" with an onclick calling history.back() without preventing the default action: the fragment navigation was applied before the asynchronous history traversal, which then only went back to the same folder URL without '#'. The Back link now targets the parent folder, so it also works when the folder was opened in a new tab (no usable history). On a plain click, when the previous history entry is the parent folder (checked with the Navigation API when available), it goes back in history instead, so no extra entry is added and the parent page state is restored. If the traversal fails, the direct link is used. Modified clicks keep the default link behavior. Grid cells now reset their link target with removeAttribute('target'): 'delete link.target' is a no-op on an HTMLAnchorElement, so a cell that had held a bookmark opened in a new tab kept target="_blank" after paging, and a folder later shown there opened in a new tab despite the 'open folder' setting. The dial URL building is shared by folder and Back links through utils.getDialUrl, removing an unreachable branch (dial.path is never empty). --- src/js/dial.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/js/dial.js b/src/js/dial.js index cd981ce..14c2dbf 100644 --- a/src/js/dial.js +++ b/src/js/dial.js @@ -60,6 +60,11 @@ utils.getPath = function(){ if(path) return path + '/'; else return '/'; }; +utils.getDialUrl = function(path){ + var url = '?bg=' + encodeURIComponent(app.settings.backgroundColor); + if(path) url += '&path=' + encodeURIComponent(path); + return url; +}; app.init = function(){ app.Messages.getSettings(function(settings){ @@ -517,7 +522,7 @@ dial.populateGrid = function(){ link.Node = null; link.className = 'Empty'; link.childNodes[0].style.backgroundImage = ''; - if(link.target) delete link.target; + link.removeAttribute('target'); link.href = null; link.onclick = null; link.removeAttribute('contextmenu'); @@ -527,9 +532,19 @@ dial.populateGrid = function(){ link.className = 'Back'; link.childNodes[0].style.backgroundImage = ''; link.childNodes[1].innerText = 'Back'; - if(link.target) delete link.target; - link.href = '#'; - link.onclick = function(){ window.history.back(); } + link.removeAttribute('target'); + var parentPath = dial.path.substring(0, dial.path.lastIndexOf('/', dial.path.length - 2)); + link.href = utils.getDialUrl(parentPath); + link.onclick = function(e){ + if(e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return; + if(!window.navigation || !navigation.canGoBack) return; + var previousUrl = navigation.entries()[navigation.currentEntry.index - 1].url; + if(!previousUrl) return; + previousUrl = new URL(previousUrl); + if(previousUrl.pathname != location.pathname || (previousUrl.searchParams.get('path') || '') != parentPath) return; + e.preventDefault(); + navigation.back().committed.catch(function(){ location.assign(link.href); }); + }; link.removeAttribute('contextmenu'); } populateFolder = function(link, node){ @@ -544,14 +559,13 @@ dial.populateGrid = function(){ link.childNodes[1].innerText = node.title; switch(app.settings.grid.openFolderMethod){ case 0: - if(link.target) delete link.target; + link.removeAttribute('target'); break; case 1: link.target = '_blank'; break; } - if(dial.path) link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(dial.path + node.title); - else link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(node.title); + link.href = utils.getDialUrl(dial.path + node.title); link.onclick = null; link.setAttribute('contextmenu', 'item'); } @@ -571,7 +585,7 @@ dial.populateGrid = function(){ link.childNodes[1].innerText = node.title; switch(app.settings.grid.openBookmarkMethod){ case 0: - if(link.target) delete link.target; + link.removeAttribute('target'); break; case 1: link.target = '_blank';