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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.