आप इसे पूरी तरह से जावास्क्रिप्ट में कर सकते हैं:
मूल प्रमाणीकरण प्रमाणीकरण को साफ़ करने के लिए IE के पास (लंबे समय के लिए) मानक API है:
document.execCommand("ClearAuthenticationCache")
जब यह काम करे तो सच्चा लौटना चाहिए। या तो झूठे, अपरिभाषित या अन्य ब्राउज़रों पर वापस लौटाता है।
नए ब्राउज़र (दिसंबर 2012 तक: क्रोम, फ़ायरफ़ॉक्स, सफारी) में "जादू" का व्यवहार है। यदि वे किसी भी फर्जी अन्य उपयोगकर्ता नाम के साथ एक सफल बुनियादी अधिकार अनुरोध देखते हैं (मान लें logout
) तो वे क्रेडेंशियल कैश को साफ़ करते हैं और संभवतः इसे उस नए फर्जी उपयोगकर्ता नाम के लिए सेट करते हैं, जिसे आपको यह सुनिश्चित करने की आवश्यकता है कि सामग्री देखने के लिए मान्य उपयोगकर्ता नाम नहीं है।
इसका मूल उदाहरण है:
var p = window.location.protocol + '//'
// current location must return 200 OK for this GET
window.location = window.location.href.replace(p, p + 'logout:password@')
उपरोक्त करने का एक "अतुल्यकालिक" तरीका logout
उपयोगकर्ता नाम का उपयोग करके एक AJAX कॉल करना है । उदाहरण:
(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*/)
आप इसे एक बुकमार्कलेट भी बना सकते हैं:
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*/);