Add: js script for external link confirmation

This commit is contained in:
Aroy-Art 2023-08-24 17:19:12 +02:00
parent e747d28d63
commit a0aba71291
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -0,0 +1,29 @@
// static/js/confirm_external_links.js
document.addEventListener("DOMContentLoaded", function () {
var externalLinks = document.querySelectorAll("a[href^='http']:not([href*='" + window.location.host + "'])");
for (var i = 0; i < externalLinks.length; i++) {
externalLinks[i].addEventListener("click", function (event) {
event.preventDefault();
var confirmationModal = new bootstrap.Modal(document.getElementById('externalLinkConfirmationModal'), {
keyboard: false
});
var externalLink = document.getElementById('externalLink');
var externalLinkShow = document.getElementById('externalLinkShow');
var originalLink = this.href;
externalLink.setAttribute('href', originalLink);
externalLinkShow.innerText = "URL: " + this.href;
confirmationModal.show();
externalLink.addEventListener('click', function () {
confirmationModal.hide();
});
});
}
});