FindBrowser

Eu escrevi este pequeno código ontem à noite para ajudar na detecção do navegador, ele força o Chrome a reportar como apenas Chrome ao usar userAgent para detecção.

http://cdpn.io/JroCs

function FindBrowser(){
/*FindBrowser:
* Requires - jQuery

* I developed this bit of code to help with browser detection in jquery, I was having trouble

* differentiating Chrome From Safari, this little function helps with that by forcing $.browser['safari']

* to report as false if chrome is found in the userAgent definition

*/

var search_str = ['chrome','firefox','safari','msie'];
var arraylen = search_str.length;
var i = 0;
while (i < arraylen){

var str = search_str[i];
var strlen = str.length;
var browserDetails = navigator.userAgent.toLowerCase();
var _search = browserDetails.search(str);
var ret_str = browserDetails.substr(_search,strlen);

if (ret_str === str){
console
.log('Succesfully found browser --> '+ ret_str);
//Here we will force chrome to report as only chrome to jQuery
if (str === 'chrome'){
$
.browser['safari'] = false;
return;
}
}
i
++;
}
}