js javascript浏览器语言检测,获取用户的浏览器语言首选项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js javascript浏览器语言检测,获取用户的浏览器语言首选项相关的知识,希望对你有一定的参考价值。
JQ - detect users browser language using http headers via ajax jsonp ajaxhttpheaders
/* * 201008051404 - brandonjp * * I was using this...but it's bad (not accurate).... // browser detect - returns the users browsers language preference function browsLang() { return ( navigator.language || navigator.userLanguage ); }; * * Thanks to DanSingerman @ javascript for detecting browser language preference - Stack Overflow http://bit.ly/czTmtO * This requires jQuery, but gives a more accurate read of the user's browser language pref * by reading the http header from the user's browser upon request to : http://ajaxhttpheaders.appspot.com/ * */ var browserLang; jQuery.ajax({ url: "http://ajaxhttpheaders.appspot.com", dataType: 'jsonp', success: function(headers) { browserLang = normaliseLang(headers['Accept-Language']); carryOnFriend(); } }); // The following function contains the real meat of the script file // But because I'm in a hurry, I'll wrap most of my file inside this function // Then we'll run this fn as a callback when everything else if finished function carryOnFriend() { // Everything else that needs to happen after the AJAX goes here jQuery(document).ready(function($) { // Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs; }); }
以上是关于js javascript浏览器语言检测,获取用户的浏览器语言首选项的主要内容,如果未能解决你的问题,请参考以下文章