Thursday, June 28, 2012

how to get browser name in Jquery/javascript

Title: JQuery Get browser name in Asp.net

Description:
While working with web application we need to set or get some browser compatibility settings as per requirement.Now i would like to describe how to resolve some design issues of asp button  control based on browser using JQuery.In Java script we have an object "navigator" ,which can be used to get the browser name in java script.Here i converted the navigator user value  to upper case letters ,then based on  condition i will filter the browser.
Javascript:
<script>
window.onload(GetBrowserDemo());
function GetBrowserDemo()
{
var btnid=document.getElementById("<%=btntest.ClientID%>");
var browservalue = navigator.userAgent.toUpperCase(); 
if(browservalue .indexOf("FIREFOX") > -1)
{ 
alert('FireFox');
btnid.val="Test"
} 
else if(browservalue .indexOf("MSIE") > -1)
{ 
alert('IE');
btnid.val="Edit";
} 
else if (browservalue .indexOf("CHROME") > -1)
{
alert('Chrome');
btnid.val="update";
} 
}
</script>
Jquery:
$(document).ready(function() {
if ($.browser.msie){
alert('It is IE');
}
if( $.browser.opera){
alert('It is Opera');
}
if ($.browser.mozilla){
alert('It is Mozilla);
}
if( $.browser.safari ){
alert('It is Safari');
}
});
}
In JQuery ,It has an object "browser" to get the current browser name .if we use the JQuery ,we  have to add the jquery reference library . Please refer this link 

Jquery browser Objet with examples

No comments:

Bel