Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the destination URL for the onbeforeunload event?

I've searched for hours, but I couldn't find a solution for this.

window.onbeforeunload = warn; 

This doesn't work:

function warn (e)  {     var destination = e.href;    alert(destination ); } 

Okay, so to clear the things. If the user clicks on a link on the page itself, it is easy, because you can add an eventhandler to all of the links onclick event, but. I want to catch the address, what the user types into the url box of the browser.

like image 938
misnyo Avatar asked Nov 06 '09 10:11

misnyo


People also ask

What is Onbeforeunload event?

The onbeforeunload event occurs when the document is about to be unloaded. This event allows you to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page. The default message that appears in the confirmation box, is different in different browsers.

What is the difference between Onbeforeunload and Onunload?

Prototype: Whereas unload is a normal event that inherits from Event , beforeunload has its own prototype, BeforeUnloadEvent .


1 Answers

Because it can't be done. The new location is private/sensitive information. Nobody wants you to know which sites they visit when they leave your site.

like image 109
Michel van Engelen Avatar answered Sep 19 '22 23:09

Michel van Engelen