开发者

Can I get operating system's measurement system (metric or US) in javascript

is there a way to measurement system using javas开发者_开发技巧cript/JQuery? I need to display some distance and speed values on the page, but It looks like that there is no such function call I can get this information.


No, you can't directly.

You could try this, though: try to get localization information from the http headers or the page (lang attribute etc.). Then you could try something like Microsoft's globalization plugin and see what you come up with.


I know of no way to do that directly. But if you can get the user's preferred locale, you can base it on that. For anything other than en-US, use metric units, and you should be OK. See:

Best way to determine user's locale within browser


One work part of the time solution only in JS is to get their Timezone and see if it's US or not. It won't work for say South America or Canada, but it will for most of the world.

You can also grab the user's language to make a guess.

if (navigator.language) { Lang=navigator.language } else { Lang=navigator.userLanguage }

Or use a service like:

http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜