Alert box OK Cancel same result

Posted on 2007-10-08
Last Modified: 2012-06-21
Here is the script
<script style="javascript">

function logOut()
    html = document.getElementsByTagName('html');
    html[0].style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
    if (confirm('Are you sure that you want to log out?')) { window.location.href='logout.php' } else { html[0].style.filter = ''};


By clicking the logout link the page is grayed out and an alert box come up asking if you want to log out, two buttons OK and Cancel, doesn't matter which one you click the result is the same you're loged out.

The question: how to fix it so when you click cancel you are actually not loged off.
Question by:gamebits
    LVL 7

    Expert Comment

    Umm... there must be something else than what you're showing us. The code seen is "correct"; it should (and does) not attempt to log you out if you click cancel (or close the shown dialog by pressing the "X" in the corner).
    LVL 28

    Author Comment

    Well you can try it yourself here

    user: test
    password: test

    after you are loged in the logout link will appear on the left side menu
    LVL 7

    Accepted Solution

    Ah, you have not overriden the default behaviour of the logout-link. Therefore; even when it asks if you wish to logout or not, no matter what, the link is followed anyway.

    You need to change



      onclick="logOut(); return false;"

    ...and it should work as you expect it to.
    LVL 28

    Author Comment

    Good job, I raised the points to the max for the extra effort, thanks.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This article shows how to read a single webpage's HTML into a string variable, and it also shows how to automate a sequence so you can read and process a list of webpages.  I was tasked with reading and parsing a series of webpages to collect some s…
    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now