Return to Snippet

Revision: 29354
at August 6, 2010 04:29 by brandonjp


Updated Code
/* 
 * 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;
	});
	
}

Revision: 29353
at July 27, 2010 23:45 by brandonjp


Initial Code
// browser detect - returns the users browsers language preference
function browsLang() {
	return ( navigator.language /* Moz */ || navigator.userLanguage /* IE */ );
};

Initial URL


Initial Description
JQ - detect users browser language using http headers via ajax jsonp ajaxhttpheaders

Initial Title
js javascript browser language detection, get the user\'s browser\'s language preference setting using jquery to detect users br

Initial Tags
http, ajax, javascript, js, textmate, browser, jquery, function

Initial Language
jQuery