shan_emails has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have a webpage (using perl, cgi) in that i set the cookies for handling username and it will expired when logout link is clicked.

But the problem is when the user use the close "X" button for closing the page this time i need to expires the cookies also.

Is there any option to delete cookies when browser window closed. (eg. using window.unload using javascript or jquery).

Any help will be appreciated.

Thanks,
Shanmugam A.
  • Comment on delete cookies when browser window closed

Replies are listed 'Best First'.
Re: delete cookies when browser window closed
by Corion (Patriarch) on Jul 27, 2010 at 16:06 UTC

    Have the cookie be a session cookie so it expires when the user closes the browser. See HTTP_cookie

      From HTTP COOKIES in the CGI module documentation: "If an expiration date isn't specified, the cookie will remain active until the user quits the browser."

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: delete cookies when browser window closed
by pajout (Curate) on Jul 28, 2010 at 07:32 UTC
    What about setting cookie with expiration in the past on unload event?

      No Javascript, no event handler, no deleted cookie. Plus unload event handlers are not very reliable. Leaving out the expiration date just works (even with killall -9 $browsername), no need for Javascript.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        I agree, afoken, but the onunload stuff I thought should be pretty good... it's included in most core libs (basically because of IE6's memory leak... you had to manually unload everything or as the user went from page to page, IE6 would get full and puke). Hm, though that's usually all IE-only code...