mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Set rel noopener and noreferrer on external links in markdown (#3666)
* Set rel noopener and noreferrer on external links in markdown * Update ha-markdown.ts * Update ha-markdown.ts
This commit is contained in:
parent
abc849f623
commit
7912f0bf9e
@ -49,13 +49,17 @@ class HaMarkdown extends UpdatingElement {
|
|||||||
|
|
||||||
// Open external links in a new window
|
// Open external links in a new window
|
||||||
if (
|
if (
|
||||||
node.nodeName === "A" &&
|
node instanceof HTMLAnchorElement &&
|
||||||
(node as HTMLAnchorElement).host !== document.location.host
|
node.host !== document.location.host
|
||||||
) {
|
) {
|
||||||
(node as HTMLAnchorElement).target = "_blank";
|
node.target = "_blank";
|
||||||
|
|
||||||
|
// protect referrer on external links and deny window.opener access for security reasons
|
||||||
|
// (see https://mathiasbynens.github.io/rel-noopener/)
|
||||||
|
node.rel = "noreferrer noopener";
|
||||||
|
|
||||||
// Fire a resize event when images loaded to notify content resized
|
// Fire a resize event when images loaded to notify content resized
|
||||||
} else if (node.nodeName === "IMG") {
|
} else if (node) {
|
||||||
node.addEventListener("load", this._resize);
|
node.addEventListener("load", this._resize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user