开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜