Tamamen JavaScript ile yapabilirsiniz:
IE, Temel Kimlik Doğrulama önbelleğini temizlemek için (uzun süre) standart API'ye sahiptir:
document.execCommand("ClearAuthenticationCache")
Çalıştığında doğru dönmelidir. Diğer tarayıcılarda false, undefined veya blows döndürür.
Yeni tarayıcılar (Aralık 2012 itibariyle: Chrome, FireFox, Safari) "sihirli" davranışa sahiptir. Herhangi bir sahte diğer kullanıcı adıyla başarılı bir temel kimlik doğrulama isteği görürlerse (diyelim logout) kimlik bilgileri önbelleğini temizler ve muhtemelen içeriği görüntülemek için geçerli bir kullanıcı adı olmadığından emin olmanız gereken yeni sahte kullanıcı adı için ayarlarlar.
Bunun temel örneği:
var p = window.location.protocol + '//'
// current location must return 200 OK for this GET
window.location = window.location.href.replace(p, p + 'logout:password@')
Yukarıdakileri yapmanın "eşzamansız" bir yolu, logoutkullanıcı adını kullanarak bir AJAX çağrısı yapmaktır . Misal:
(function(safeLocation){
var outcome, u, m = "You should be logged out now.";
// IE has a simple solution for it - API:
try { outcome = document.execCommand("ClearAuthenticationCache") }catch(e){}
// Other browsers need a larger solution - AJAX call with special user name - 'logout'.
if (!outcome) {
// Let's create an xmlhttp object
outcome = (function(x){
if (x) {
// the reason we use "random" value for password is
// that browsers cache requests. changing
// password effectively behaves like cache-busing.
x.open("HEAD", safeLocation || location.href, true, "logout", (new Date()).getTime().toString())
x.send("")
// x.abort()
return 1 // this is **speculative** "We are done."
} else {
return
}
})(window.XMLHttpRequest ? new window.XMLHttpRequest() : ( window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : u ))
}
if (!outcome) {
m = "Your browser is too old or too weird to support log out functionality. Close all windows and restart the browser."
}
alert(m)
// return !!outcome
})(/*if present URI does not return 200 OK for GET, set some other 200 OK location here*/)
Bir yer işareti de yapabilirsiniz:
javascript:(function(c){var a,b="You should be logged out now.";try{a=document.execCommand("ClearAuthenticationCache")}catch(d){}a||((a=window.XMLHttpRequest?new window.XMLHttpRequest:window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):void 0)?(a.open("HEAD",c||location.href,!0,"logout",(new Date).getTime().toString()),a.send(""),a=1):a=void 0);a||(b="Your browser is too old or too weird to support log out functionality. Close all windows and restart the browser.");alert(b)})(/*pass safeLocation here if you need*/);