not able to get and store screen resolution
I am using following code to save screen-resolution in cookie
va开发者_StackOverflowr the_cookie="screen_resolution="+screen.width+"x"+screen.height+";expires="+today.setDate(today.getDate()+1);
document.cookie=the_cookie;
But some-how, it not working on browsers like IE 7 and 8.
Any idea, why it's not working? Is screen.width and screen.height don't retrieve screen-resolution on all browsers, or they have browser dependencies.
Change the code to something like this:
today.setDate(today.getDate() + 1);
var the_cookie = "screen_resolution=" + screen.width + "x" + screen.height + ";expires=" + today;
document.cookie = the_cookie;
The setDate
function won't return the new date as far as I know, so it means your cookie had no expire date... probably some browsers have a default, and some will treat such cookie as invalid.
精彩评论