简体   繁体   中英

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? 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.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

Or you could use a geo IP service (IP is known only server side): http://freegeoip.net/json/

要获取浏览器窗口的区域设置和UI显示的语言,您可以使用:

chrome.i18n.getUILanguage()

Have you checked in the google developers api:

https://developer.chrome.com/extensions/api_index

I guess it uses geolocation :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM