简体   繁体   English

在Chrome扩展程序中,如何从Chrome浏览器中准确检索用户的区域/区域/国家/地区?

[英]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.

相关问题 如何从另一台服务器的浏览器扩展 (Chrome) 获取 JSON 数据? - How can I get JSON data from a browser extension (Chrome) from another server? 我可以从Chrome扩展程序中获取可用的语言环境翻译列表吗? - Can I get a list of available locale translations from my Chrome extension? 如何从Chrome扩展程序到浏览器页面模拟对生成的“警报”或“确认”的操作 - How can i simulate action on generated “alert” or “confirm” from chrome extension to browser page 如何在chrome扩展程序中保存用户输入? - How can I save user input in my chrome extension? 在Chrome扩展程序中,确定用户是否单击了浏览器的“后退”或“前进”按钮 - In Chrome extension determine if the user clicked the browser's Back or Forward button 如何在后台获取chrome扩展程序的内容脚本? - How can I get chrome extension's content script to in the background? 如何修改用户提交的带有Chrome扩展程序的搜索输入中的查询? - How can I modify the query from a user submitted search input with a Chrome extension? 如何通过Chrome扩展程序从网页中使用Node的请求库? - How can I use Node's request library from within a webpage through a Chrome Extension? 是否可以通过 JavaScript 中的浏览器确定操作系统中设置的用户区域设置的**国家/地区**? - Is it possible to determine the user locale's **country** as set in the OS from the browser in JavaScript? 如何确定Chrome扩展程序是否位于内容脚本的弹出窗口中? - How can I determine if a Chrome extension is in a popup from the content script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM