Display a “Leaving Website” page when a user is leaving our domain
In our AEM website, we want to display a “Leaving Website” page when a user is leaving our domain. What would be the recommended way to code this?
In our AEM website, we want to display a “Leaving Website” page when a user is leaving our domain. What would be the recommended way to code this?
You can achieve this by using JavaScript to detect when a user clicks on
any Button
any Anchor / Navigation link
CTA button click
closing the browser window -- that leads to a different domain.
except closing the window - remaining three has configured with new domain URL.
you can write a Javascript
sample
document.querySelectorAll('a').forEach(function(link) {
link.addEventListener('click', function(event) {
var linkhasOtherDomain = link.hostname;
var currentDomain = window.location.hostname;
if (linkhasOtherDomain !== currentDomain) {
event.preventDefault();
var userConfirmation = confirm('You are leaving our website. Are you sure you want to continue?');
if (userConfirmation) {
window.location.href = link.href;
}
}
});
});
for window close event - write a different condition.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.