js判断cookie是否存在

JavaScript019

js判断cookie是否存在,第1张

var cookie = document.cookie

//cookie是个字符串型的 判断其长度

if(cookie.length == 0 ){

alert('不存在cookie')

}

<a target="_blank" href="http://down.123.com/abc.pdf" onclick="return chkcookies()">下载PDF</a>

<script>

function chkcookies()

{

var NameOfCookie="abc_2010_cookie"

var c = document.cookie.indexOf(NameOfCookie+"=")

if (c != -1)

{

return true

}

else

{

alert("您还没注册")

location.href="http://www.123.com/reg.html"

}

return false

}

</script>