When a visitor attempts to close the tab, they are presented with a message by this code:
window.onbeforeunload = function() {
return "Are you sure you want to leave?";
}
Unfortunately, I am struggling to make this code work:
window.onbeforeunload = function() {
window.location.replace("http://www.example.com");
}
What could be preventing this code from successfully redirecting the visitor to example.com when attempting to close the tab? Is there a solution to fix this issue?