Javascript Firefox4中的基本身份验证未注销
我使用的是基本身份验证,希望通过javascript调用注销以清除漏洞。我编写了以下函数,该函数在IE和Firefox 3.6中运行,但在Firefox 4.0中不起作用。有什么解决办法吗Javascript Firefox4中的基本身份验证未注销,javascript,login,basic-authentication,Javascript,Login,Basic Authentication,我使用的是基本身份验证,希望通过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.
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 to false如果非ie浏览器的用户代理中包含msie,则indexOfmsie也会成功,opera希望根据设置执行此操作