Detect which browser our script is running :
BrowserFinding.html:
<html>
<html>
<head>
<script>
function detectBrowser(){
var val = navigator.userAgent.toLowerCase();
if(val.indexOf("firefox") > -1)
{
alert("This is Firefox. Write Firefox code here........")
}
else if(val.indexOf("chrome") > -1)
{
alert("This is Google Chrome. Write Google Chrome code here.............")
}
else if(val.indexOf("opera") > -1)
{
alert("This is Opera. Write Opera code here..............")
}
else if(val.indexOf("msie") > -1)
{
alert("This is Internet Explorer. Write Internet Explorer code here..........")
}
else if(val.indexOf("safari") > -1)
{
alert("This is Safari. Write Safari code here..........")
}
};
window.onload=detectBrowser();
</script>
</head>
<body>
</body>
</html>
Output:
In IE :
This is Internet Explorer. Write Internet Explorer code here.........
In FF:
This is Firefox. Write Firefox code here.........
In Chrome:
This is Google Chrome. Write Google Chrome code here........
BrowserFinding.html:
<html>
<html>
<head>
<script>
function detectBrowser(){
var val = navigator.userAgent.toLowerCase();
if(val.indexOf("firefox") > -1)
{
alert("This is Firefox. Write Firefox code here........")
}
else if(val.indexOf("chrome") > -1)
{
alert("This is Google Chrome. Write Google Chrome code here.............")
}
else if(val.indexOf("opera") > -1)
{
alert("This is Opera. Write Opera code here..............")
}
else if(val.indexOf("msie") > -1)
{
alert("This is Internet Explorer. Write Internet Explorer code here..........")
}
else if(val.indexOf("safari") > -1)
{
alert("This is Safari. Write Safari code here..........")
}
};
window.onload=detectBrowser();
</script>
</head>
<body>
</body>
</html>
Output:
In IE :
This is Internet Explorer. Write Internet Explorer code here.........
In FF:
This is Firefox. Write Firefox code here.........
In Chrome:
This is Google Chrome. Write Google Chrome code here........
No comments:
Post a Comment