问题描述
|
我正在使用基本身份验证,并希望使用javascript调用注销(清除凭据)。我编写了以下功能,该功能在IE和Firefox 3.6中有效,但现在在Firefox 4.0中不起作用。有什么解决方法
function logout()
{
try{
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf(\"msie\") != -1) {
// IE clear HTTP Authentication
document.execCommand(\"ClearauthenticationCache\");
}
else {
var xmlhttp = createXMLObject();
xmlhttp.open(\"GET\",\".force_logout_offer_login_mozilla\",true,\"logout\",\"\");
xmlhttp.send(\"\");
xmlhttp.abort();
}
// window.location = \"/rest/\";
} catch(e) {
}
}
function createXMLObject() {
try {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
}
} catch (e) {
xmlhttp=false
}
return xmlhttp;
}
解决方法
一种解决方法是显示警报窗口以暂停脚本。
// Let\'s send the request to the server
xmlhttp.send(\"\");
// Let\'s abort the request
var index = agt.indexOf(\"firefox\");
if(index > 0)
{
var version = agt.substr(index,agt.length-index).split(\"/\");
var vnum = parseInt(version[1]);
// alert window for Firefox > 4
if(vnum > 4) alert(\"Firefox logout\");
}
xmlhttp.abort();
如果出现以下错误:
Fehler: uncaught exception: [Exception... \"prompt aborted by user\" nsresult: \"0x80040111 (NS_ERROR_NOT_AVAILABLE)\" location: \"JS frame :: resource://gre/components/nsPrompter.js :: openTabPrompt :: line 468\" data: no]
您必须输入about:config
并设置
prompts.tab_modal.enabled
至false