FindBrowser
I wrote this little bit of code last night to help with browser detection, it forces Chrome to report as only Chrome when using userAgent for detection.
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++;
}
}Written by Mike Young
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#