#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    223
    Rep Power
    12

    Navigator.cookieEnabled not workiing on IE


    As usual, IE sucks one thousand times.

    I tried using navigator.cookieEnabled on Firefox, and it works great, awesome. But when I go to IE having the cookies disabled, the page just freezes and I got no alert, not even an error message (I wish this browser doesn't exists anymore).

    Here is my function:

    Code:
    function detect_cookies(){
      var cookieEnabled=(navigator.cookieEnabled)? true : false
      //if not IE4+ nor NS6+
      if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
        document.cookie="testcookie"
        cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
      }
    
      if(cookieEnabled){
        document.getElementById("form_login").action="login.php";
        document.getElementById("form_login").submit();
      }else{
        window.alert("Please enable your cookies.");
      }
    }
    I call the function into an action, like this:

    <form method="POST" action="javascript:detect_cookies()">

    Any ideas guys? How can I make it work on IE?. As far as I know, this function is supported in IE4+ and NS6+.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Location
    England
    Posts
    398
    Rep Power
    72
    Originally Posted by Takitei
    <form method="POST" action="javascript:detect_cookies()">
    Having a function call in the form's action could cause unpredictable results. I would call the function via the onsubmit handler.
    I tried using navigator.cookieEnabled on Firefox, and it works great, awesome. But when I go to IE having the cookies disabled, the page just freezes and I got no alert, not even an error message
    Why use a non standard-property, when the conventional test:
    Code:
        document.cookie="testcookie"
        cookieEnabled=(document.cookie.indexOf("testcookie")!=-1);
    works universally?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    223
    Rep Power
    12
    Yeah, well actually my function is using the conventional test, but it still not working on IE. I changed the call of the function from the "action" to the "onsubmit" event, but it still working on FF but not on IE. On IE with the cookies disabled, the form just get submitted and no alert pops up.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Location
    England
    Posts
    398
    Rep Power
    72
    Originally Posted by Takitei
    Yeah, well actually my function is using the conventional test, but it still not working on IE. I changed the call of the function from the "action" to the "onsubmit" event, but it still working on FF but not on IE. On IE with the cookies disabled, the form just get submitted and no alert pops up.
    Then you'll need to post your current code, including the form.

IMN logo majestic logo threadwatch logo seochat tools logo