https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq5HidDzAsS7uR_9yKjVdXTjUGO6W6Jkex29wGSfxpfVPajhasyg5_kI0ckgRIT1t5p7ru5cQHPI4e4oB1GuO-NIgtAMWixttfrpzOoClZDbwhOItS60CigeZY6iQvRLBRIwob7J7tz-c/s1600/grey_plaid.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd6lq5DsKcEDDFRsdiSHvKe6_g9EQazXsNwA-6Mrv48_mbpzGqjXlxj_DI5XIwxYkqFcL_iN2OgHrRDECq3BrM89ajfDUpunYRI3Rq1pPL9pXXzb_jyIhbmc5nvqoHGGuwhVA3EgVRls8/s1600/grey_plaid.png
Browser Detection
To establish the actual name of the user's Web browser, we can use the navigator.appName
and navigator.userAgent
properties.
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Firefox (and some other browsers) may return the string Netscape
as the value of navigator.appName
for compatibility with Netscape Navigator.
However, that navigator.userAgent
may be spoofed, too – that is, clients may substitute virtually any string for their userAgent.
browserName = Firefox
majorVersion = 5
fullVersion = 5.0
visit
www.javascripter.net/faq/browsern.htm for the script.
:P
//here is the source code that performed the browser detection:
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+6);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) <
(verOffset=nAgt.lastIndexOf('/')) )
{
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
fullVersion=fullVersion.substring(0,ix);
majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
fullVersion = ''+parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion,10);
}
document.write(''
+'browserName = '+browserName+'<br>'
+'majorVersion = '+majorVersion+'<br>'
+'fullVersion = '+fullVersion+'<br>'
+'navigator.appName = '+navigator.appName+'<br>'
+'navigator.userAgent = '+navigator.userAgent+'<br>'
)
Script Hasil Modif
function detectBrowser(){
var nVer=navigator.appVersion;
var nAgt=navigator.userAgent;
var browserName =navigator.appName;
var fullVersion =parseFloat(navigator.appVersion);
var majorVersion=parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
if((verOffset=nAgt.indexOf("Opera"))!=-1){
browserName="Opera";
fullVersion=nAgt.substring(verOffset+6);
if((verOffset=nAgt.indexOf("Version"))!=-1){fullVersion=nAgt.substring(verOffset+8)}
}else if((verOffset=nAgt.indexOf("MSIE"))!=-1){
browserName="Microsoft Internet Explorer";
fullVersion=nAgt.substring(verOffset+5);
}else if((verOffset=nAgt.indexOf("Chrome"))!=-1){
browserName="Chrome";
fullVersion=nAgt.substring(verOffset+7);
}else if((verOffset=nAgt.indexOf("Safari"))!=-1){
browserName="Safari";
fullVersion=nAgt.substring(verOffset+7);
if((verOffset=nAgt.indexOf("Version"))!=-1){fullVersion=nAgt.substring(verOffset+8)}
}else if((verOffset=nAgt.indexOf("Firefox"))!=-1){
browserName="Firefox";
fullVersion=nAgt.substring(verOffset+8);
}else if( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ){
browserName=nAgt.substring(nameOffset,verOffset);
fullVersion=nAgt.substring(verOffset+1);
if(browserName.toLowerCase()==browserName.toUpperCase()){browserName=navigator.appName}
}
if((ix=fullVersion.indexOf(";"))!=-1){fullVersion=fullVersion.substring(0,ix)}
if((ix=fullVersion.indexOf(" "))!=-1){fullVersion=fullVersion.substring(0,ix)}
majorVersion=parseInt(fullVersion,10);
if(isNaN(majorVersion)){
fullVersion=parseFloat(navigator.appVersion);
majorVersion=parseInt(navigator.appVersion,10);
}
var tulis=browserName+' '+majorVersion;
return tulis;
}
document.write(detectBrowser());
Firefox 5
0 komentar:
Posting Komentar