Determining your browser :

Here’s a more advanced example that determines which browser the user has and lets you execute code depending on browser type to display the browser version. This example puts to use the if and else statements as well as several built-in JavaScript functions that handle strings. In JavaScript, text strings are considered objects, and they have some built-in properties and methods that make life easier.





span style="font-weight:bold;">Determining your browser :/span In angle brackets


script language=”javascript” In angle brackets

var versionBegin, versionEnd

function checkBrowser()

{

if(navigator.appName == “Netscape”) {

if(navigator.userAgent.indexOf(“Firefox”) > 0) {

versionBegin = navigator.userAgent.indexOf(“Firefox”) +

“Firefox”.length + 1;

versionEnd = navigator.userAgent.length;

document.getElementById(“targetDiv”).innerHTML =

“You have Firefox “ +

navigator.userAgent.substring(versionBegin, versionEnd);

}

}

if (navigator.appName == “Microsoft Internet Explorer”) {

versionBegin = navigator.userAgent.indexOf(“MSIE “) +

“MSIE “.length;

if(navigator.userAgent.indexOf(“;”, versionBegin) > 0) {

versionEnd = navigator.userAgent.indexOf(“;”, versionBegin);

} else {

versionEnd = navigator.userAgent.indexOf(“)”, versionBegin)

+ 2;

}

document.getElementById(“targetDiv”).innerHTML =

“You have Internet Explorer “ +

navigator.userAgent.substring(versionBegin, versionEnd);

}

}

/script In angle brackets



body onload=”checkBrowser()” ; Use this in angle brackets..

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.