Skip to content

Commit

Permalink
Update external_links.js to fix link behavior on MASVS page (#2475)
Browse files Browse the repository at this point in the history
* Update external_links.js to fix link behavior on MASVS page

This PR modifies the code to enhance the user experience on the MASVS page (https://mas.owasp.org/MASVS/) by ensuring that external links open in a new tab, similar to the behavior on the MASTG page (https://mas.owasp.org/MASTG/). 

This change involves updating the checking if the path starts with '/MASTG' or '/MASVS' and applying the necessary attributes to external links accordingly.

* add document#.subscribe to call every time the page navigate
  • Loading branch information
rmRizki authored Feb 7, 2024
1 parent 526d17e commit 560da51
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions docs/javascripts/external_links.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
if ((window.location.hostname === 'mas.owasp.org' || window.location.hostname === 'localhost') && window.location.pathname.startsWith('/MASTG')) {
const links = document.links;
document$.subscribe(function () {
if (
(window.location.hostname === 'mas.owasp.org' || window.location.hostname === 'localhost') &&
(window.location.pathname.startsWith('/MASTG') || window.location.pathname.startsWith('/MASVS'))
) {
const links = document.links;

for (let i = 0; i < links.length; i++) {
const link = links[i];

// Exclude links to mas.owasp.org
if (link.hostname === 'mas.owasp.org') {
continue; // Skip this link
}

if (link.hostname !== window.location.hostname) {
link.setAttribute('target', '_blank');

// Create an icon element (e.g., a small arrow)
const icon = document.createElement('span');
icon.textContent = ' ↗';

// Append the icon to the link
link.appendChild(icon);
for (let i = 0; i < links.length; i++) {
const link = links[i];

// Exclude links to mas.owasp.org
if (link.hostname === 'mas.owasp.org') {
continue; // Skip this link
}

if (link.hostname !== window.location.hostname) {
link.setAttribute('target', '_blank');

// Create an icon element (e.g., a small arrow)
const icon = document.createElement('span');
icon.textContent = ' ↗';

// Append the icon to the link
link.appendChild(icon);
}
}
}
}
})

0 comments on commit 560da51

Please sign in to comment.