HTTPAuth Logout in Chrome, Firefox and IE with jQuery

$( function (){
     $( '#user_logout' ).on( 'click' , function (e){
         // HTTPAuth Logout code based on: http://tom-mcgee.com/blog/archives/4435
         e.preventDefault();
         try {
             // This is for Firefox
             $.ajax({
                 // This can be any path on your same domain which requires HTTPAuth
                 url: "/any/path" ,
                 username: 'reset' ,
                 password: 'reset' ,
                 // If the return is 401, refresh the page to request new details.
                 statusCode: { 401: function () {
                     document.location = document.location;
                     }
                 }
             });
         } catch (exception) {
             // Firefox throws an exception since we didn't handle anything but a 401 above
             // This line works only in IE
             if (!document.execCommand( "ClearAuthenticationCache" )) {
                 // exeCommand returns false if it didn't work (which happens in Chrome) so as a last
                 // resort refresh the page providing new, invalid details.
                 document.location = "http://reset:reset@" + document.location.hostname + document.location.pathname;
             }
         }
     });
});

转自:http://patabugen.co.uk/2013/12/09/httpauth-logout-in-chrome-firefox-and-ie-with-jquery/

你可能感兴趣的:(注销,HTTPAuth)