문제

this current piece of script to confirm whether a user wants to log out is not fully working in Safari on Mac.

function log_out()
{
    ht = document.getElementsByTagName("html");
    ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
    if (confirm('Are you sure you want to log out?'))
    {

        return true;
    }
    else
    {
        ht[0].style.filter = "";
                return false;
    }
}

It works when the user confirm they want to logout, Ok, but when the user clicks cancel, they are still logged out.

Any ideas?

Thanks in advance!

도움이 되었습니까?

해결책

Put the return instruction in front of the log_out call

<a class="rnavtab" href="?do=logout" onclick="return log_out()">Log out</a>

다른 팁

Ok, but when the user clicks cancel, they are still logged out.

After seeing your code in the comment you posted:

<a class="rnavtab" href="?do=logout" onclick="log_out()">Log out</a>

The ?do=logout is triggered irrspective of whether a user confirms or not. Try putting a hash instead:

<a class="rnavtab" href="#" onclick="log_out()">Log out</a>

You can later on redirect user like this:

window.location = '?do=logout';
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top