Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts

    Session cookie not ending in IE

    Cookie name is "viewStatus" value saved is 1

    Closing all windows should end the session but on the reopening cookie page I find the session cookie is still alive.

    If I alert(document.cookie) I get viewStatus = 1

    If I rename the cookie to say "vStatus" and close the window when I reopen it and alert(document.cookie) I get

    viewstatus=1 vStatus=1

    any ideas?

    This only happens in IE ( as always)

    PS

    I just did a little experiment, I closed all windows, created a new file with just

    <script>
    alert(document.cookie)
    </script>

    in it then opened the file and still got

    viewstatus=1 vStatus=1

    I know I did not have this problem before because I have a session cookie example on my site and that does not work now so is it something new that is wrong with IE
    Last edited by Mr J; 06-28-2006 at 11:13 AM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    And how are you setting the cookie?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Here's some code, clicking the link reveals a div and sets the session cookie.

    When I close and then reopen the page the cookie still exists when the session cookie should expire on closing the window, the only way I can get it to expire is to reboot my pc

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Document Title</TITLE>

    <
    script type="text/javascript">
    <!--

    function 
    getDivStatus(){

    alert("Cookie Value = "+getCookie("viewStatus"))

    if(
    getCookie("viewStatus")==1){

    showHide(0)

    }

    }

    function 
    getCookie(name){
    var 
    cookieName name "="

    var cookieValue ""
    if(document.cookie.length 0){
    startIndex document.cookie.indexOf(cookieName)

    if(
    startIndex != -1) {
    startIndex += cookieName.length

    endIndex 
    document.cookie.indexOf(";"startIndex)

    if(
    endIndex == -1){
    endIndex document.cookie.length
    }

    cookieValue=unescape(document.cookie.substring(startIndexendIndex))

    }

    }

    return 
    cookieValue

    }

    function 
    showHide(num){

    if(
    document.getElementById("div"+num).style.display=="none"){
    document.getElementById("div"+num).style.display="block"
    }
    else{
    document.getElementById("div"+num).style.display="none"
    }

    document.cookie="viewStatus=1"

    }

    //-->
    </script>


    </HEAD>
    <BODY  onload="getDivStatus()">

    <a href="#null" onclick="showHide(0)">Show Div 1</a><BR>
    <div id="div0" style="width:300px;height:50px;background-color:#55aa55;display:none">Div 1</div>

    </BODY>
    </HTML> 
    Last edited by Mr J; 06-28-2006 at 03:55 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.


  •  

    Posting Permissions

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