如何在(经典)ASP中检测屏幕分辨率

时间:2021-07-07 01:39:02

I want to detect users' screen size and pass this into a charting application (Chart Director by http://www.advsofteng.com) to control how big an image to display.

我想检测用户的屏幕大小并将其传递给图表应用程序(图表总监http://www.advsofteng.com)来控制图像的显示大小。

I have to use ASP, but I can only think to use JavaScript to detect screen-size and then pass this into the server-side script. Is there an easier way?

我必须使用ASP,但我只能考虑使用JavaScript来检测屏幕大小,然后将其传递到服务器端脚本中。有没有更简单的方法?

Thanks

6 个解决方案

#1


4  

No, the server knows nothing about the client other than basic info like IP and browser version. Screen resolution can easily be determined via javascript and passed to the server though, using ajax, or via form submission.

不,除了IP和浏览器版本等基本信息之外,服务器对客户端一无所知。屏幕分辨率可以通过javascript轻松确定,然后使用ajax或表单提交传递给服务器。

#2


3  

Here's a couple of links that should help

这里有几个应该有用的链接

http://www.javascriptkit.com/howto/newtech3.shtml

http://www.devcity.net/Articles/64/1/screenresolution.aspx

#3


2  

Here is my simple solution:

这是我的简单解决方案:

javascript code:

document.cookie = "screen_w=" + screen.availWidth ;
document.cookie = "screen_h=" + screen.availHeight;

asp code:

screen_w = request.Cookies("screen_w")
screen_h = request.Cookies("screen_h")

#4


0  

No, this is not possible for desktop browsers. I suggest embedding an image that's appropriate for typical screen resolutions, then detecting the canvas size, and rewriting the image's src attribute to reflect that.

不,这对桌面浏览器来说是不可能的。我建议嵌入一个适合典型屏幕分辨率的图像,然后检测画布大小,并重写图像的src属性以反映这一点。

In any case, you don't want to look at the screen resolution, you want to look at the canvas size. Not everybody uses their browser with a maximised window, especially those with large screens. If you use the screen resolution, then you'll end up serving images that are way too big for some people.

在任何情况下,您都不希望查看屏幕分辨率,而是要查看画布大小。并非所有人都使用带有最大化窗口的浏览器,尤其是那些大屏幕的浏览器。如果您使用屏幕分辨率,那么您最终将提供的图像对某些人来说太大了。

#5


0  

You can't get the users screen size only the browser window size, and thats doable using javascript.

您无法仅通过浏览器窗口大小获取用户屏幕大小,并且可以使用javascript。

#6


0  

The best way that I have found to do this is to create a dummy asp page which simply has the following javascript code in the header:

我发现这样做的最好方法是创建一个虚拟的asp页面,它在标题中只有以下javascript代码:

<script type="text/javascript" language="JavaScript">

    document.cookie = "screen_w=" + screen.width;
        location.href = "second_page.asp"

</script>

Then in second_page.asp you can lookup the cookie, which was set in the first page. If you set and then request in the same page, it won't work first time.

然后在second_page.asp中,您可以查找在第一页中设置的cookie。如果您在同一页面中设置然后请求,则第一次无法使用。

myscreenwidth = request.Cookies("screen_w")

myscreenwidth = request.Cookies(“screen_w”)

#1


4  

No, the server knows nothing about the client other than basic info like IP and browser version. Screen resolution can easily be determined via javascript and passed to the server though, using ajax, or via form submission.

不,除了IP和浏览器版本等基本信息之外,服务器对客户端一无所知。屏幕分辨率可以通过javascript轻松确定,然后使用ajax或表单提交传递给服务器。

#2


3  

Here's a couple of links that should help

这里有几个应该有用的链接

http://www.javascriptkit.com/howto/newtech3.shtml

http://www.devcity.net/Articles/64/1/screenresolution.aspx

#3


2  

Here is my simple solution:

这是我的简单解决方案:

javascript code:

document.cookie = "screen_w=" + screen.availWidth ;
document.cookie = "screen_h=" + screen.availHeight;

asp code:

screen_w = request.Cookies("screen_w")
screen_h = request.Cookies("screen_h")

#4


0  

No, this is not possible for desktop browsers. I suggest embedding an image that's appropriate for typical screen resolutions, then detecting the canvas size, and rewriting the image's src attribute to reflect that.

不,这对桌面浏览器来说是不可能的。我建议嵌入一个适合典型屏幕分辨率的图像,然后检测画布大小,并重写图像的src属性以反映这一点。

In any case, you don't want to look at the screen resolution, you want to look at the canvas size. Not everybody uses their browser with a maximised window, especially those with large screens. If you use the screen resolution, then you'll end up serving images that are way too big for some people.

在任何情况下,您都不希望查看屏幕分辨率,而是要查看画布大小。并非所有人都使用带有最大化窗口的浏览器,尤其是那些大屏幕的浏览器。如果您使用屏幕分辨率,那么您最终将提供的图像对某些人来说太大了。

#5


0  

You can't get the users screen size only the browser window size, and thats doable using javascript.

您无法仅通过浏览器窗口大小获取用户屏幕大小,并且可以使用javascript。

#6


0  

The best way that I have found to do this is to create a dummy asp page which simply has the following javascript code in the header:

我发现这样做的最好方法是创建一个虚拟的asp页面,它在标题中只有以下javascript代码:

<script type="text/javascript" language="JavaScript">

    document.cookie = "screen_w=" + screen.width;
        location.href = "second_page.asp"

</script>

Then in second_page.asp you can lookup the cookie, which was set in the first page. If you set and then request in the same page, it won't work first time.

然后在second_page.asp中,您可以查找在第一页中设置的cookie。如果您在同一页面中设置然后请求,则第一次无法使用。

myscreenwidth = request.Cookies("screen_w")

myscreenwidth = request.Cookies(“screen_w”)