开发者

Detect/infer visitor base currency using Javascript?

Is there a reasonable way to detect or infer the v开发者_C百科isitor'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?


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.


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜