Saturday, June 9, 2012

Log out of basic auth with JavaScript

Ever wanted to log out of a basic authentication session with only JavaScript?

The following code requires jQuery, but it is of course possible to hack something together with plain JavaScript.

$.get(document.URL.replace(/(https?:\/\/)/, '$1logout@'));

I have figured out that this doesn't work all the time, and it seems unreliable. However, it may be used as a last resort.

No comments:

Post a Comment