http basic authentication “log out”

前端 未结 8 1351
悲&欢浪女
悲&欢浪女 2020-11-28 04:23

HTTP basic authentication credentials are stored until the browser is closed, but is there a way to remove the credentials before the browser is closed?

I read about

8条回答
  •  悲&欢浪女
    2020-11-28 04:47

    You can delete credentials with JavaScript:

        $("#logout").click(function(){
            try {
                document.execCommand("ClearAuthenticationCache");
                window.location.href('/logout.html'); // page with logout message somewhere in not protected directory
            } catch (exception) {}
        });
    

    This code works only in IE. This is the reason why try/catch block is added there. Also, for the same reason the logout link you should show for IE users only:

        
    

    And for other users my suggestion is something like:

        
    [Logout]

提交回复
热议问题