Basic Authentication – LogOut via Javascript
I found this procedure on Stackoverflow (http://stackoverflow.com/questions/233507/how-to-log-out-user-from-web-site-using-basic-authentication) that allow clear authentication saved in the browser for your site:
function ClearAuthentication(LogOffPage)
{
var IsInternetExplorer = false;
admin = 'n';
try
{
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") != -1) { IsInternetExplorer = true; }
}
catch(e)
{
IsInternetExplorer = false;
};
if (IsInternetExplorer)
{
// Logoff Internet Explorer
document.execCommand("ClearAuthenticationCache");
window.location = LogOffPage;
}
else
{
// Logoff every other browsers
$.ajax({
username: 'unknown',
password: 'WrongPassword',
url: '/',
type: 'GET',
beforeSend: function(xhr)
{
xhr.setRequestHeader("Authorization", "Basic AAAAAAAAAAAAAAAAAAA=");
},
error: function(err)
{
//alert(window.location.protocol + '//xxxx:xxxx@' + window.location.host + ':' + window.location.port + LogOffPage);
window.location = window.location.protocol + '//xxxx:xxxx@' + window.location.host + LogOffPage;
window.location = window.location.protocol + '//' + window.location.host + LogOffPage;
}
});
}
}
i tried it on chrome and firefox and function as aspect:
Back to main page