0

I need to remove a cookie on browser close event. I am trying to write the following code

window.onunload = function () { document.cookie = "empIdDialIntg=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; } 

This works fine.But I want to remove the cookie only on browser close event(when clicked on X) not on unload. So if any new site is opened on the same tab,it should persist my cookie value.But with unload my cookie value is removed if i paste new site on the same tab.

Is there any such event in javascript ?

Thanks in advance

4
  • 1
    have you tried window.onbeforeunload Commented Jun 8, 2015 at 7:16
  • 3
    @Newinjava Have you tried reading the question? Commented Jun 8, 2015 at 7:17
  • 1
    Non need to do this: just use a session cookie Commented Jun 8, 2015 at 7:19
  • 1
    See also: stackoverflow.com/questions/1025935/…. Not all browsers support onunload Commented Jun 8, 2015 at 7:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.