Quick note for anyone who has stumbled into the Anvil Extras Quill JS issue, whereby if you click a link in your rich text component created from the HTML, the window is replaced and can’t go back to your app page.
Drop this in your native libraries to override the behaviour and open new tabs instead:
<script>
document.addEventListener("click", function(event) {
// Check if the clicked element is a link
if (event.target.tagName === "A") {
// Prevent the default behavior
event.preventDefault();
// Open the link in a new tab
window.open(event.target.href, "_blank");
}
});
</script>
It might be hacky, but it saves a headache!
It DOESN’T impact navigation in your SPA, but it may impact hash routing, for those using it.
Edit:
To make sure this only happens with links going outside your app domain, you can use:
<script>
document.addEventListener("click", function(event) {
// Check if the clicked element is a link
if (event.target.tagName === "A") {
// Check if the link domain is different from the app origin domain
if (event.target.host !== window.location.host) {
// Prevent the default behavior
event.preventDefault();
// Open the link in a new tab
window.open(event.target.href, "_blank");
}
}
});
</script>