PDA

View Full Version : oh boy... i will die!


alaios
09-14-2002, 02:25 PM
hi i have these problems!
i have found some games which
works in n4 but it doesnot in ns6!!Why?
Which is the fastest way to detect if the browser is Netscape?For example using only a logical expression?

umm
09-14-2002, 08:49 PM
1. No idea why your games gon't work.

2. Do you mean regular expression? Here's a basic object detection method:


<script language="javascript" type="text/javascript">
<!--
//Netscape Navigator 4x
var n4=(document.layers)?true:false;
//ie4
var ie4=(document.all && !document.getElementById)?true:false;
//ie5x, ie6, N6, Moz1, Opera6
var v6=(document.getElementById)?true:false;

//test function
function getBrowser(){
if(n4){
alert("N4")
} else if(ie4){
alert("IE4")
}else if(v6){
alert("Latest Crop")
}
}
//-->
</script>

alaios
09-15-2002, 11:34 AM
please tell me what is this?
)?true:false;

joh6nn
09-15-2002, 11:43 AM
"? :" is a short way of writing if{} else {}

(foo) ? bar : uhoh;

that's the same as

if (foo) {
bar;
}
else {
uhoh;
}

alaios
09-15-2002, 08:27 PM
thx!!and if i want to detect ie 5?and opera 5.12?

umm
09-15-2002, 09:31 PM
try something like this for Opera 5x:


var op5 = (navigator.userAgent.indexOf("Opera")!= -1 &&
(parseInt(navigator.appVersion.charAt(0)) ==5))


As for ie5x, you can use a simialr approach as above or use

ie5=(getElementById && document.all)?true:false;


Detection by object or version both have pitfalls. Just be sure to test your scripts properly in different browsers to make sure nothing unwanted happens.