屏幕分辨率检测

问题描述:

I know that similar questions were asked but this is different.

Intro: i'm triyng to make an website with adaptive designs (3 templates for 3 widths intervals as follows: 1200+px, 600-1200px, 600-px).

Problem: i have a really hard time with user screen width detection. I' know that only js can detect user screen size so i tried two ways of detection. 1. First i used a cookie in order to store the width but because cookie becomes active only after refresh i need to refresh the page. 2. Second o used to send width as param with GET but again i need to refresh the page in order to send params.

So the question is: is there a way to get screen size without page refresh (the value to be stored in a cookie/session). I need the proper template to be delivered on first visit of page.

If there is no solution (only with refrest needed) for width detection how can a solve the problem for crawlers so they won't see the redirect.

我知道提出了类似的问题,但这是不同的。 p>

简介 :我正在努力建立一个具有自适应设计的网站(3个宽度间隔的模板如下:1200 + px,600-1200px,600-px)。 p>

问题:我有 用户屏幕宽度检测非常困难。 我知道只有js可以检测用户的屏幕大小,所以我尝试了两种检测方式。 1。 首先我使用cookie来存储宽度,但因为cookie只在刷新后才变为活动状态我需要刷新页面。 2。 第二个o用于通过GET发送宽度作为参数但是我需要刷新页面才能发送参数。 p>

所以问题是:有没有办法获得没有页面的屏幕大小 refresh(要存储在cookie /会话中的值)。 我需要在第一次访问页面时提供正确的模板。 p>

如果没有解决方案(只需要使用refrest)进行宽度检测,如何解决爬虫的问题,以便他们赢了 看不到重定向。 p> div>

I think you're approaching this the wrong way. Surely css @media queries are the way to do this?

If for some reason you do need the width in Javascript, then you can do

jQuery:

$(document).width();

JavaScript:

document.body.clientWidth

I would revise your methodology if you can though..?

I ended up using a DDR (Device Description Repository), exactly this one : http://wurfl.sourceforge.net/ It works good and gives a lot of etails exept on firefox. No CSS OR JS required for use.