You are here: HomeForums » Javascript » Tips and tricks » Use javascript to detect the type of browser

Use javascript to detect the type of browser (2 posts)

in Forums » Javascript » Tips and tricks

thdadmin (administrator)

Use these when you want to detect the browser type using javascript:

// IE browser
var ie  = document.all != null;  //ie4 and above
var ie5 = document.getElementById && document.all;
var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0);

// Netscape browser
var ns4 = document.layers != null;
var ns6 = document.getElementById && !document.all;
var ns  = ns4 || ns6;

// Firefox browser
var ff  = !document.layers && !document.all;

// Opera browser
var op  = navigator.userAgent.indexOf("opera")>0;
var op7 = op && operaVersion() <= 7;
var op8 = op && operaVersion() >= 8;
Posted 1 month ago #

ioana (Administrator)

For opera detection you can also figure out the version:

function operaVer() {
	agent = navigator.userAgent;
	idx = agent.indexOf("opera");
	if (idx>-1) {
		return parseInt(agent.subString(idx+6,idx+7));
	}
}
Posted 1 month ago #

Reply

You must log in to post.