Javascript Browser Navigator check cookies on <body> load event

Introduction

Using the onload event to deal with cookies:

View in separate window

<!DOCTYPE html>
<html>
<body onload="checkCookies()">

<p id="demo"></p>

<script>
function checkCookies() {/*from   ww w  .  jav  a2 s .com*/
  var text = "";
  if (navigator.cookieEnabled == true) {
    text = "Cookies are enabled.";
  } else {
    text = "Cookies are not enabled.";
  }
  document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>



PreviousNext

Related