12 lines
342 B
TypeScript
12 lines
342 B
TypeScript
export const setExternalLinksToOpenInNewTab = (
|
|
anchors: NodeListOf<HTMLAnchorElement>
|
|
) => {
|
|
const httpRegex = /^https?:\/\//i;
|
|
anchors.forEach((anchor: HTMLAnchorElement) => {
|
|
if (httpRegex.test(anchor.href)) {
|
|
anchor.setAttribute("target", "_blank");
|
|
anchor.setAttribute("rel", "noopener noreferrer");
|
|
}
|
|
});
|
|
};
|