The following example are going to create an object to store the client
Information,
I would like to new the object to init all the properties by function:
setProperty()
Can I set the value to the object without using the global variable ?
Thank you.
///---------------The object -------------------------------
function clientENV {
var detect = navigator.userAgent.toLowerCase();
this.os;
this.browser;
this.version;
setProperty();
}
///-------------Function------------------------------------
var theString, place, OS, browser, version;
function setProperty() {
if (checkIt('msie')) browser = "Internet Explorer"
else if (checkIt('Firefox')) browser = "Safari"
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('konqueror')) {
browser = "Konqueror";
OS = "Linux";
} else if (!checkIt('compatible')) {
browser = "Netscape Navigator"
version = detect.charAt(8);
}
else browser = "An unknown browser";
if (!version) version = detect.charAt(place + thestring.length);
if (!OS) {
if (checkIt('linux')) OS = "Linux";
else if (checkIt('x11')) OS = "Unix";
else if (checkIt('mac')) OS = "Mac"
else if (checkIt('win')) OS = "Windows"
else OS = "an unknown operating system";
}
}
function checkIt(string) {
place = detect.indexOf(string) + 1;
thestring = string;
return place;
}