Bajrang
Bajrang

Reputation: 8629

how to run php code before closing the browser

I would like to run a small php script before closing the browser. I don't know it's possible or not. I am trying with this but when I refresh the webpage then also running the code

<body onbeforeunload="xajax_closeBrowser();" > 

Its not necessary to run ajax , may be simple php code.

Thanks a lot.

Upvotes: 0

Views: 515

Answers (2)

Oyeme
Oyeme

Reputation: 11225

$(window).unload( function () { //ajax call });

The unload event is sent to the window element when the user navigates away from the page.

P.S Only for away navigation.No another way.

Upvotes: 1

lanzz
lanzz

Reputation: 43158

There is no way to tell if the browser is closing or the user is simply navigating away. onbeforeunload is run in both cases, as it indicates the current page context is being discarded for whatever reason. There is no event to catch browser termination.

Upvotes: 1

Related Questions