Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting cookie value for user screen size? #182

Open
clemsontiger opened this issue Apr 22, 2015 · 2 comments
Open

Not getting cookie value for user screen size? #182

clemsontiger opened this issue Apr 22, 2015 · 2 comments

Comments

@clemsontiger
Copy link

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?

@faebe
Copy link

faebe commented Jun 15, 2015

Same problem here

@faebe
Copy link

faebe commented Jun 15, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants