SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Help with Logout Redirect

    Hello,

    I have a "Logout" button, which when clicked, is supposed to do two things: 1) Reset the "Login" cookie, and 2) redirect the user to the login page. My code currently looks like:

    Code:
    function confirmLogout()
    {
        if (window.confirm("Are you sure you want to log out?"))
        {
        setCookie("Login", 0);
        window.location = "login.asp";
        }
    }
    The resetting of the cookie works fine, but I don't get redirected to the login page. What am I doing wrong?


    Thanks,


    DoughBoy

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try replacing

    window.location = "login.asp";

    with

    top.location.href = "login.asp";
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    beetle,

    Thanks for the prompt reply. Unfortunately, your suggestion still produces the same result. I remain on the same page after clicking "OK".


    DoughBoy

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just realized my error. My original Javascript code works fine. My problem was with the Feedback link itself:

    I initially had something like:

    <a href="#" onClick="confirmLogout()">Feedback</a>

    Which I changed to:

    <a href="javascript:confirmLogout()">Feedback</a>

    Why did the first one cause problems? I use similar syntax in other parts of my site (e.g., pop-up windows).


    DoughBoy

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, you could do it this way...
    Code:
    function confirmLogout()
    {
        if ( confirm( "Are you sure you want to log out?" ) )
        {
            setCookie( "Login", 0 );
            return true;
        }
        else
            return false;
    }
    
    <a href="logout.asp" onclick="return confirmLogout();">link</a>
    Then you aren't relying 100% on javascript for getting the user to your logout page.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •