Adaptive-Images icon indicating copy to clipboard operation
Adaptive-Images copied to clipboard

Not getting cookie value for user screen size?

Open clemsontiger opened this issue 10 years ago • 2 comments

Can't seem to get this to work.

If I force the resolution it seems to work, but if I don't, it doesn't.

Works when I do: document.cookie='resolution=480'; path=/';

Does not work, when I do: document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';

I've got the line before any other javascript. htaccess and adaptive-images is working due to it correctly resizing and stored in ai-cache when forcing the resolution..So I can only guess that the other snippet is not actually getting the resolution correctly? Like it's not correctly doing number 5 in the details instructions: "The PHP file looks for a cookie and finds that the user has a maximum screen size of 480px." How can I test what resolution it's picking up? What "cookie" is this referring to as its source for resolution?

clemsontiger avatar Apr 22 '15 16:04 clemsontiger

Same problem here

faebe avatar Jun 15 '15 16:06 faebe

Resolution:

screen.width outputs you the actual SCREEN width, not the VIEWPORT width. You can use window.innerWidth to get the current browser frame.

Code

Example with Retina support:

document.cookie='resolution='+Math.max(window.innerWidth,window.innerHeight)+("devicePixelRatio" in window ? ","+devicePixelRatio : ",1")+'; path=/';

EDIT (15.06.15)

I just found out window.innerWidth causes problems with high DPI devices (the value doubles). Looks like you are stuck with screen.width

faebe avatar Jun 15 '15 16:06 faebe