diff --git a/cigaradvisor/blocks/imagecta/imagecta.js b/cigaradvisor/blocks/imagecta/imagecta.js index f3d8d444..db34d461 100644 --- a/cigaradvisor/blocks/imagecta/imagecta.js +++ b/cigaradvisor/blocks/imagecta/imagecta.js @@ -11,7 +11,8 @@ export default async function decorate(block) { anchor.append(picture); const link = block.querySelector('a').getAttribute('href'); anchor.setAttribute('href', link); - anchor.setAttribute('target', isExternal(link)); + anchor.setAttribute('target', isExternal(link) ? '_blank' : '_self'); + anchor.setAttribute('title', img.alt); children.push(anchor); block.replaceChildren(...children); } diff --git a/cigaradvisor/scripts/scripts.js b/cigaradvisor/scripts/scripts.js index 7a146b62..fa44ccdb 100644 --- a/cigaradvisor/scripts/scripts.js +++ b/cigaradvisor/scripts/scripts.js @@ -93,10 +93,13 @@ export function decorateMain(main) { buildTwoColumnGrid(main); } -export function isExternal(url) { - const anchor = document.createElement('a'); - anchor.href = url; - return (anchor.hostname !== window.location.hostname) ? '_blank' : '_self'; +export function isExternal(path) { + try { + const url = new URL(path); + return window.location.hostname !== url.hostname; + } catch (error) { + return false; + } } /**