PDA

View Full Version : set font problem for different computer user


fattat
02-22-2009, 04:27 AM
if want my website font use arial for mac computer
and helvetica font for pc computer,
how i set for it?

do anyone know the javascript?
can give me the script?

davidj
02-22-2009, 09:54 AM
javascript function will let you change a class name referencing the CSS


function sub(){

var OSName="Unknown OS";


if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";

if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";

if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";

if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

switch(OSName){

case 'Windows': classn = "windowsClass"; break;
case 'MacOS': classn = "macClass"; break;
case 'UNIX': classn = "UNIXClass"; break;
case 'Linux': classn = "linuxClass"; break;

}

document.setAttribute("class", classn);
document.setAttribute("className", classn);
}

Corrosive
02-22-2009, 10:03 AM
javascript function will let you change a class name referencing the CSS


function sub(){

var OSName="Unknown OS";


if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";

if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";

if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";

if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

switch(OSName){

case 'Windows': classn = "windowsClass"; break;
case 'MacOS': classn = "macClass"; break;
case 'UNIX': classn = "UNIXClass"; break;
case 'Linux': classn = "linuxClass"; break;

}

document.setAttribute("class", classn);
document.setAttribute("className", classn);
}


Nice snippet DJ. I'm having that :)

d a v e
02-22-2009, 11:37 AM
of course you could just set it to helvetica, arial, sans-serif ... not sure why you would want to give mac users arial when the could have helvetica as a first choice :)

fattat
02-22-2009, 11:41 AM
of course you could just set it to helvetica, arial, sans-serif ... not sure why you would want to give mac users arial when the could have helvetica as a first choice :)

i just give a example
because some of the font mac have but pc dont have

d a v e
02-22-2009, 12:01 PM
then you could just set it like this in your style sheet
body {
font-family: Arial, Helvetica, sans-serif;
}

replace with your desired fonts in the order of preference

davidj
02-22-2009, 02:02 PM
shucks

always try to program my way out of stuff

like a big cluts with mallet fingers

d a v e
02-22-2009, 02:38 PM
well davidj it's good to offer more complex alternatives as well - others might find it useful!

domedia
02-22-2009, 08:38 PM
Best practice is to just use one CSS line where you set the rank of font faces to use, ending with a generic font family. Only in rare situation do you need to sniff browser nowadays I think..

Corrosive, aren't you already using jQuery?
http://docs.jquery.com/Utilities/jQuery.browser