troubleshooting Question

Clear Cookie using JavaScript when browser is close

Avatar of bradley525
bradley525 asked on
34 Comments1 Solution12410 ViewsLast Modified:
Hello I am using the following code to clear a cookie when my browser closes, the only problem is that it clears the cookie when I navigate to another page.

Is there a way to only call the function if the browser closes?

$(window).on('beforeunload', function(e) {
return "You will now be logged out,";

$(window).on('unload', function(e) {
document.cookie = 'hodan_current_cookie=; expires=Fri, 3 Aug 2012 20:47:11 UTC; path=/'
Join our community to see this answer!
Unlock 1 Answer and 34 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 34 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros