From 7c5c491da8ed15ebf1337413ac0e76f97425f7e1 Mon Sep 17 00:00:00 2001 From: Vidip Singh <112854574+vidipsingh@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:26:09 +0530 Subject: [PATCH] Fix dynamic favicon path handling using root URL - Updated favicon handling to dynamically set the favicon path based on the root URL. - Fixed the issue in the commit 245ea8c where favicon would not load correctly on subdirectory pages by calculating the site root URL using window location. Fixes #507 --- js/main.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/main.js b/js/main.js index 481828e4..4050c5fe 100755 --- a/js/main.js +++ b/js/main.js @@ -23,13 +23,16 @@ $(document).ready(function () { if (logoID < 10) { logoID = "0" + logoID; } - - // Extract the base path from the current favicon href - var currentHref = defaultIcon.getAttribute('href'); - var basePath = currentHref.substring(0, currentHref.lastIndexOf('/') + 1); - // Update only the filename portion while keeping the original path - defaultIcon.href = basePath + 'favicon_' + logoID + '.png'; + var rootUrl = ''; + var baseTag = document.querySelector('base'); + if (baseTag && baseTag.href) { + rootUrl = baseTag.href; + } else { + rootUrl = window.location.protocol + '//' + window.location.host + '/'; + } + + defaultIcon.href = rootUrl + 'assets/favicon_' + logoID + '.png'; } var h = document.querySelector('.logo1').innerHTML;