Browser sniffing, o functie pentru DOM (document object model) de pe vremea lui Netscape s.a. Prima chestie era deja chemata dintr-o alta functie prezentata data trecuta (sooo, sorry daca ati testat ceva si nu v-a mers din cauza asta 🙂 ). Here we go:
[sourcecode language=’jscript’]
/* ———– EVALUATION ————– */
//browser sniffer: conditiile sunt if (is.ns) etc.
function appName() {
var agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.ns = ((agent.indexOf(‘mozilla’)!=-1) && ((agent.indexOf(‘spoofer’)==-1) && (agent.indexOf(‘compatible’) == -1)));
this.ns3 = (this.ns && (this.major >= 3));
this.ns4 = (this.ns && (this.major >= 4));
this.ie = (agent.indexOf(“msie”) != -1);
this.ie3 = (this.ie && (this.major == 2));
this.ie4 = (this.ie && (this.major >= 4));
this.op3 = (agent.indexOf(“opera”) != -1);
this.win = (agent.indexOf(“win”)!=-1);
this.mac = (agent.indexOf(“mac”)!=-1);
this.unix = (agent.indexOf(“x11”)!=-1);
}
var is= new appName();
/* short version
function appName() {
var agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.ns = ((agent.indexOf(‘mozilla’)!=-1) && ((agent.indexOf(‘spoofer’) == -1) && (agent.indexOf(‘compatible’) == -1)));
this.ns3 = (this.ns && (this.major >= 3));
this.ns4 = (this.ns && (this.major >= 4));
this.ie = (agent.indexOf(“msie”) != -1);
this.ie4 = (this.ie && (this.major >= 4));
}
var is= new appName()
*/
//window width and height
function winW(frameName){
if (frameName == null){
if(is.ns4){ return innerWidth; }else if (is.ie4){
returnValue= (document.body.clientWidth) ? document.body.clientWidth : screen.width;
return returnValue;
}
}else{
if(is.ns4){ return eval(” + frameName + ‘.innerWidth’); }else if (is.ie4){
return eval(” + frameName + ‘.document.body.clientWidth’)
}
}
}
function winH(frameName){
if (frameName == null){
if(is.ns4){ return innerHeight; }else if (is.ie4){
returnValue= (document.body.clientHeight) ? document.body.clientHeight : screen.height;
return returnValue;
}
}else{
if(is.ns4){ return eval(” + frameName + ‘.innerHeight’); }else if (is.ie4){
return eval(” + frameName + ‘.document.body.clientHeight’)
}
}
}
//DOM : this is needed for DHTML
var doc, sty, htm;
var frm= “top.”
if(is.ns4) {
doc = “document”;
sty = “”;
htm = “.document”
}else if(is.ie4) {
doc = “document.all”;
sty = “.style”;
htm = “”
}
//get the name of a file from its absolute adress (sometimes it’s usefull)
function getName(fileAdress){
if (fileAdress == null){
fileAdress= window.location
}
temp0= new String(fileAdress);
temp1= temp0.split(“/”);
retValue= temp1[temp1.length-1];
return retValue;
}
[/sourcecode]
Iar acum disclaimerul: unele dintre chestiile de mai sus sunt utilizate de multi oameni care scriu scripturi in JavaScript; cel putin unele sunt probabil date ca exemple prin tot felul de manuale s.a.m.d. alte chestii au fost folosite, probabil, doar de Gramo, dar s-ar fi putut gandi oricine la ele. Nimic din ce gasiti aici n-are copyright, asa cum n-are copyright roata. Use it as you wish.
De cati ani e scriptul asta ?
@Pirahna: You know what? Daca iti foloseste la ceva, bine, daca nu, ktnxbye, nu ma freca la cap, ok?
p.s.: Si vezi ca nu e vorba de un script, ci de niste functii care pot fi folosite in cadrul unui script, ceea ce e altceva.
p.p.s.: Acum pe bune, ce importanta are de cati ani e? Nu ti l-am bagat pe gat. Mai lipseste sa-mi spui ca e mult mai misto sa faci chestiile in Flash decat in JavaScript. 🙂
p.p.p.s: Gandeste-te asa: poate informatiile astea ii vor fi utile cuiva, chiar daca tu strambi din nas. Sau poate nu ii vor fi utile nimanui. So what? Poate vreau sa le gasesc usor pe net mai tarziu si mi le-am pus pe blog. What do you care? E blogul tau? Nope. So?
oarecum cam offtopic:
voi 2 ati facut asta?
Looooooooooooooooooooool! 🙂
Pingback: Cateva functii utile in JavaScript (3) « Gramo’s World
de acord cu Pirahna…
Decat functii d’astea…