Is there a way to determine the timezone for a user agent without javasript?
是否有一种方法可以确定没有javasript的用户代理的时区?
normally, i would execute this snippet of javascript:
正常情况下,我会执行这段javascript代码:
<script type="text/javascript" language="JavaScript">
var offset = new Date();
document.write('<input type="hidden" id="clientTzOffset"
name="clientTzOffset" value="' + offset.getTimezoneOffset() + '"/>');
</script>
However, for a lot of mobiles and clients, JS is either not existant or turned off. Is there something clever I can do or am I reduced to "tell me where you are and what timzeone you are in?"
然而,对于很多手机和客户来说,JS要么不存在,要么就被关闭了。我能做点什么聪明的事情,要么就只能“告诉我你在哪里,你在哪里?”
4 个解决方案
#1
2
Maybe with a server side language you could do an IP lookup, and then determine from their country what timezone they could be in.
也许使用服务器端语言,您可以进行IP查找,然后从他们的国家确定他们可能在什么时区。
I'd imagine this could be problematic, though.
我想这可能是个问题。
If going down this road, this question (and answers) may be of assistance.
如果沿着这条路走下去,这个问题(和答案)可能会得到帮助。
Getting the location from an IP address
从IP地址获取位置
#2
5
Use both. Have javascript set the default value of a list or text field. The percentage of people without javascript is so small the burden is tiny.
同时使用。让javascript设置列表或文本字段的默认值。没有javascript的人比例很小,负担也很小。
I was going to say "Use the request Date: header" but that's a response header only it seems.
我想说“使用请求日期:header”,但这似乎只是一个响应header。
#3
3
I thought of another solution but it is a little complex. Set up some fake HEAD requests with a max-age: 1 response header to coerce the browser into re-fetching them. You should then receive an if-modified-since header from any modern browser like so:
我想到了另一种解决办法,但有点复杂。使用max-age: 1响应头设置一些伪头请求,迫使浏览器重新取回它们。然后,您应该收到一个if-modified,因为任何现代浏览器的标题都是这样:
If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
Just be careful not to send any Last-Modified headers with the first response because
请注意不要发送带有第一个响应的最后修改的头部,因为
To get best results when sending an If- Modified-Since header field for cache validation, clients are advised to use the exact date string received in a previous Last- Modified header field whenever possible.
为了在发送If- Modified- since header字段进行缓存验证时获得最佳结果,建议客户端尽可能使用上一次修改的header字段中收到的确切日期字符串。
Note the "whenever possible" disclaimer. This, and other parts of the header description imply that the client will use its own clock when it doesn't know anything of the servers.
注意“尽可能”的免责声明。这一点以及header描述的其他部分表明,当客户端不知道任何服务器时,它将使用自己的时钟。
With the right combination of headers this could actually work very well.
有了正确的头部组合,这实际上可以很好地工作。
EDIT: Tried some tests with FF but couldn't find a valid combination of headers to trigger an if-modified-since in client time. FF only sends the header if it got a last-modified header previously and then it just reflects the value back (even if it isn't a valid date).
编辑:使用FF尝试了一些测试,但是没有找到一个有效的头部组合来触发if-modified-since在客户端时间。FF只有在之前得到最后修改的header时才发送header,然后才返回值(即使它不是一个有效的日期)。
#4
1
I've seen a website where instead of asking what timezone the user was in it simply asked "pick the correct time" and it showed them a list of times. It's a subtle difference from "what timezone are you in" but much easier to understand. Unfortunately I can't find the website anymore
我曾在一个网站上看到,用户没有问他所在的时区,只是问他“选择正确的时间”,结果显示了一个时间列表。这与“你在哪个时区”有微妙的区别,但更容易理解。不幸的是,我再也找不到这个网站了
#1
2
Maybe with a server side language you could do an IP lookup, and then determine from their country what timezone they could be in.
也许使用服务器端语言,您可以进行IP查找,然后从他们的国家确定他们可能在什么时区。
I'd imagine this could be problematic, though.
我想这可能是个问题。
If going down this road, this question (and answers) may be of assistance.
如果沿着这条路走下去,这个问题(和答案)可能会得到帮助。
Getting the location from an IP address
从IP地址获取位置
#2
5
Use both. Have javascript set the default value of a list or text field. The percentage of people without javascript is so small the burden is tiny.
同时使用。让javascript设置列表或文本字段的默认值。没有javascript的人比例很小,负担也很小。
I was going to say "Use the request Date: header" but that's a response header only it seems.
我想说“使用请求日期:header”,但这似乎只是一个响应header。
#3
3
I thought of another solution but it is a little complex. Set up some fake HEAD requests with a max-age: 1 response header to coerce the browser into re-fetching them. You should then receive an if-modified-since header from any modern browser like so:
我想到了另一种解决办法,但有点复杂。使用max-age: 1响应头设置一些伪头请求,迫使浏览器重新取回它们。然后,您应该收到一个if-modified,因为任何现代浏览器的标题都是这样:
If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
Just be careful not to send any Last-Modified headers with the first response because
请注意不要发送带有第一个响应的最后修改的头部,因为
To get best results when sending an If- Modified-Since header field for cache validation, clients are advised to use the exact date string received in a previous Last- Modified header field whenever possible.
为了在发送If- Modified- since header字段进行缓存验证时获得最佳结果,建议客户端尽可能使用上一次修改的header字段中收到的确切日期字符串。
Note the "whenever possible" disclaimer. This, and other parts of the header description imply that the client will use its own clock when it doesn't know anything of the servers.
注意“尽可能”的免责声明。这一点以及header描述的其他部分表明,当客户端不知道任何服务器时,它将使用自己的时钟。
With the right combination of headers this could actually work very well.
有了正确的头部组合,这实际上可以很好地工作。
EDIT: Tried some tests with FF but couldn't find a valid combination of headers to trigger an if-modified-since in client time. FF only sends the header if it got a last-modified header previously and then it just reflects the value back (even if it isn't a valid date).
编辑:使用FF尝试了一些测试,但是没有找到一个有效的头部组合来触发if-modified-since在客户端时间。FF只有在之前得到最后修改的header时才发送header,然后才返回值(即使它不是一个有效的日期)。
#4
1
I've seen a website where instead of asking what timezone the user was in it simply asked "pick the correct time" and it showed them a list of times. It's a subtle difference from "what timezone are you in" but much easier to understand. Unfortunately I can't find the website anymore
我曾在一个网站上看到,用户没有问他所在的时区,只是问他“选择正确的时间”,结果显示了一个时间列表。这与“你在哪个时区”有微妙的区别,但更容易理解。不幸的是,我再也找不到这个网站了