[英]In a Chrome Extension, how can I accurately retrieve the user's region/locale/country from their Chrome browser?
How does Google detect the user's country to set the user's search page accordingly? Google如何检测用户的国家/地区以相应地设置用户的搜索页面? I have searched around and cannot find a simple way of doing it.
我四处搜寻,找不到一种简单的方法。
You can get the languages, which the user has set in the Chrome settings, like this: 您可以获取用户在Chrome设置中设置的语言,如下所示:
chrome.i18n.getAcceptLanguages(function (list) {
console.log(list);
});
For location, there is the location API (HTML5) - but the user must agree to share the location for it to work: http://html5demos.com/geo 对于位置,有位置API(HTML5) - 但用户必须同意共享其工作位置: http : //html5demos.com/geo
Or you could use a geo IP service (IP is known only server side): http://freegeoip.net/json/ 或者你可以使用地理IP服务(IP只知道服务器端): http : //freegeoip.net/json/
要获取浏览器窗口的区域设置和UI显示的语言,您可以使用:
chrome.i18n.getUILanguage()
Have you checked in the google developers api: 你有没有检查过谷歌开发者api:
https://developer.chrome.com/extensions/api_index https://developer.chrome.com/extensions/api_index
I guess it uses geolocation :) 我想它使用地理位置:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.