On Before Unload not getting before close notice or alert or trigger

Live Link

I am in chrome:

window.onbeforeunload = function() {
	var message = "You are my captive you cant leave";
	return message;
}

I got the clue to move ahead from here.

What I was anticipating was that I will get a trigger on trying to close the tab, but that has not happened.
Am I missing some basic fundamentals or something else is going wrong?

Yeah, you can’t do that anymore.

2 Likes

Thank you so much. Is there any thing else we can try? some other JS events?

Nope. Bad guys have ruined that for us.
You’ll only get a default message from the browser now.

1 Like

6 posts were split to a new topic: What is the difference between “X” and “Client X”

Hi there sir, I was able to get things done not by that function, but by mouseleave function.

var mouseMoveY = 0;
document.addEventListener("mouseleave", mlfunction);
function mlfunction(){
	if (mouseMoveY < 1) {
		alert("You are my captive you cant leave");		
	}
}

Live Link here.

Still, I am figuring out how can I restrict that such even should fire only once. so that visitors should not suffer from annoyance.

… sooo… if mouseMoveY were to be set to something >= 1…

Ctrl+W to close the tab is my kryptonite to that technique. I’ll never know you had that message.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.