So I do simple JS function like
function writeCookie()
{
var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
document.cookie=the_cookie
}
how tm make sure that users_resolution is set?
You could write a function like so:
function getCookie(cName) {
var cVal = document.cookie.match('(?:^|;) ?' + cName + '=([^;]*)(?:;|$)');
if (!cVal) {
return "";
} else {
return cVal[1];
}
}
Then, after you have set the cookie, you can call getCookie()
and test it's return value, if it's equal to an empty string, or ""
, which is false
, then the cookie doesn't exist. Otherwise you've got a valid cookie value.
The above paragraph in code:
var cookie = getCookie("users_resolution");
if (!cookie) {
// cookie doesn't exist
} else {
// cookie exists
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With