From 2dc4a4b80db78773cc020a0c1e685f27d29459bf Mon Sep 17 00:00:00 2001 From: Dhanus Date: Wed, 13 Mar 2024 20:05:53 +0530 Subject: [PATCH] [chore] fixes --- .../openwisp-notifications/js/notifications.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/openwisp_notifications/static/openwisp-notifications/js/notifications.js b/openwisp_notifications/static/openwisp-notifications/js/notifications.js index b670a582..bb276f32 100644 --- a/openwisp_notifications/static/openwisp-notifications/js/notifications.js +++ b/openwisp_notifications/static/openwisp-notifications/js/notifications.js @@ -208,15 +208,16 @@ function notificationWidget($) { } klass = notificationReadStatus.get(elem.id); + // Used to convert absolute URLs in notification messages to relative paths function convertMessageWithRelativeURL(htmlString) { const parser = new DOMParser(); - const doc = parser.parseFromString(htmlString, "text/html"); - const links = doc.querySelectorAll("a"); + const doc = parser.parseFromString(htmlString, 'text/html'); + const links = doc.querySelectorAll('a'); links.forEach((link) => { - const absoluteUrl = link.getAttribute("href"); - if (absoluteUrl) { - const url = new URL(absoluteUrl); - link.setAttribute("href", url.pathname); + let url = link.getAttribute('href'); + if (url) { + url = new URL(url); + link.setAttribute('href', url.pathname); } }); return doc.body.innerHTML;