使用 JavaScript 检测/推断访客基础货币?
是否有合理的方法来使用 JavaScript 检测或推断访问者的基础货币?
我正在考虑使用 IP 地理位置和时区检测。您是否知道任何现有的库/方法或替代方案?
Is there a reasonable way to detect or infer the visitor's base currency using Javascript?
I'm thinking of using IP geolocation and timezone detection. Do you know of any existing libraries / methods for this, or alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,没有办法纯粹用 JavaScript 来做到这一点。
我认为最简单的方法是调用服务器端脚本,该脚本使用您选择的脚本语言的本地化函数根据 Accept-Language 标头确定货币。不过,将 Accept-Language 用于语言以外的任何事物都是值得商榷的。我个人认为这很好,只要您为访问者提供一种切换货币的方法即可。
IP 地理定位也可能是一种可行的替代方案,但我不完全确定这在全世界范围内的准确性。再次强调,一定要为访问者提供一种切换货币的方法。
There is no way to do it purely with JavaScript that I know of.
I think the easiest way is to invoke a server-side script which determines currency based on the Accept-Language header, using your scripting-langauge of choice's localization functions. Using Accept-Language for anything more than language is debatable though. Personally I think it's fine, as long as you provide the visitor with a way to switch currencies.
IP geolocation may also be a viable alternative, but I'm not entirely sure how accurate this would be throughout the world. Again, just be sure to provide the visitor with a way to switch currencies.
据我所知,没有办法使用 javascript 获取用户的 IP 或任何其他“地理位置”信息。但是,您可以使用
.getTimezoneOffset()
获取其本地时区偏移量afaik there is no way to get the user's IP or any other "geolocation" information with javascript. However, you can get their local timezone offset by using
.getTimezoneOffset()