js javascript浏览器语言检测,获取用户的浏览器语言首选项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js javascript浏览器语言检测,获取用户的浏览器语言首选项相关的知识,希望对你有一定的参考价值。

JQ - detect users browser language using http headers via ajax jsonp ajaxhttpheaders
  1. /*
  2.  * 201008051404 - brandonjp
  3.  *
  4.  * I was using this...but it's bad (not accurate)....
  5.  
  6. // browser detect - returns the users browsers language preference
  7. function browsLang() {
  8. return ( navigator.language || navigator.userLanguage );
  9. };
  10.  
  11.  *
  12.  * Thanks to DanSingerman @ javascript for detecting browser language preference - Stack Overflow http://bit.ly/czTmtO
  13.  * This requires jQuery, but gives a more accurate read of the user's browser language pref
  14.  * by reading the http header from the user's browser upon request to : http://ajaxhttpheaders.appspot.com/
  15.  *
  16.  */
  17.  
  18. var browserLang;
  19.  
  20. jQuery.ajax({
  21. url: "http://ajaxhttpheaders.appspot.com",
  22. dataType: 'jsonp',
  23. success: function(headers) {
  24. browserLang = normaliseLang(headers['Accept-Language']);
  25. carryOnFriend();
  26. }
  27. });
  28.  
  29.  
  30. // The following function contains the real meat of the script file
  31. // But because I'm in a hurry, I'll wrap most of my file inside this function
  32. // Then we'll run this fn as a callback when everything else if finished
  33.  
  34. function carryOnFriend() {
  35.  
  36. // Everything else that needs to happen after the AJAX goes here
  37.  
  38. jQuery(document).ready(function($) {
  39. // Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs;
  40. });
  41.  
  42. }

以上是关于js javascript浏览器语言检测,获取用户的浏览器语言首选项的主要内容,如果未能解决你的问题,请参考以下文章

初识JavaScript

JS基础(JavaScript三大特点基本数据类型检测逻辑运算符的短路运算几大循环结构的特点)

反正有没有使用javascript检测操作系统语言?

JavaScript

java scrapt

python前端JavaScript入门及进阶