From 7b18919564a420ed578dded0dd5ac85891d66ad5 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 29 May 2024 10:12:37 +0530 Subject: [PATCH] Tag external links to open in a separate window on the Desktop app Previously clicking inline links would open the URL directly in the Desktop app. This was strange and it didn't provide any way to go back to Khoj desktop app UI from the opened link --- src/interface/desktop/chat.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index a2a49ea1..eee29a99 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -385,6 +385,16 @@ let anchorElements = element.querySelectorAll('a'); anchorElements.forEach((anchorElement) => { + // Tag external links to open in separate window + if ( + !anchorElement.href.startsWith("./") && + !anchorElement.href.startsWith("#") && + !anchorElement.href.startsWith("/") + ) { + anchorElement.setAttribute('target', '_blank'); + anchorElement.setAttribute('rel', 'noopener noreferrer'); + } + // Add the class "inline-chat-link" to each element anchorElement.classList.add("inline-chat-link"); });