Skip to content

Commit 2168768

Browse files
committed
DEV: adds noopener rel to external links
If a link is set to open in a new tab, automatically add `rel="noopener"` to it.
1 parent 5032b08 commit 2168768

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

javascripts/discourse/initializers/initialize-for-header-icon-links.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
const className = `header-icon-${dasherize(fragments[0])}`;
1818
const viewClass = fragments[3].toLowerCase();
1919
const target = fragments[4].toLowerCase() === "blank" ? "_blank" : "";
20+
const rel = target ? "noopener" : "";
2021
const isLastLink =
2122
link === links[links.length - 1] ? ".last-custom-icon" : "";
2223
const selector = `li.custom-header-icon-link.${className}.${viewClass}${isLastLink}`;
@@ -29,6 +30,9 @@ export default {
2930
href,
3031
title,
3132
target,
33+
attributes: {
34+
rel,
35+
},
3236
},
3337
icon
3438
),

0 commit comments

Comments
 (0)