VBV-489: Open external links in new tab in assignment
This commit is contained in:
parent
06a3706d29
commit
bc011e47be
|
|
@ -4,7 +4,7 @@ import { useCircleStore } from "@/stores/circle";
|
||||||
import type { LearningContent } from "@/types";
|
import type { LearningContent } from "@/types";
|
||||||
import * as log from "loglevel";
|
import * as log from "loglevel";
|
||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import { onMounted, ref, watch } from "vue";
|
import { getCurrentInstance, onMounted, onUpdated, ref, watch } from "vue";
|
||||||
|
|
||||||
log.debug("LearningContentView created");
|
log.debug("LearningContentView created");
|
||||||
|
|
||||||
|
|
@ -52,6 +52,24 @@ onMounted(async () => {
|
||||||
);
|
);
|
||||||
await loadLearningContent();
|
await loadLearningContent();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUpdated(() => {
|
||||||
|
const vueInstance = getCurrentInstance();
|
||||||
|
if (vueInstance) {
|
||||||
|
// VBV-489: open external links in new tab
|
||||||
|
const rootElement: HTMLElement = vueInstance.proxy?.$el;
|
||||||
|
const anchors = rootElement.querySelectorAll("a");
|
||||||
|
anchors.forEach((anchor: HTMLAnchorElement) => {
|
||||||
|
if (
|
||||||
|
/^https?\:\/\//i.test(anchor.href) &&
|
||||||
|
!anchor.href.includes(window.location.hostname)
|
||||||
|
) {
|
||||||
|
anchor.setAttribute("target", "_blank");
|
||||||
|
anchor.setAttribute("rel", "noopener noreferrer");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue