I have a web site (written in PHP) that my users need to log into, and I want to be sure that they log out when they’re done. So, I have a JavaScript method that deletes the PHP session cookies, and I want to call that method (a) right before the user either closes the browser window (i.e., the DOM Window object) or (b) points their browser to a site outside of my domain. Part (a) is pretty simple using the Window.onclose method, but I can’t figure out how to do part (b). The problem is that I can’t get any of the Window events to distinguish between when the user is leaving my domain and when he’s going to a different page in my domain. I’ve seen this on some web sites (like, banking web site for example) but does anyone know how I’d actually implement it?
I have a web site (written in PHP) that my users need to log
Share
This blog post is about just that.
If you’re using prototype, the code will look something like this. (taken from blog post)