Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q351 How can I detect a Mac computer and use a larger font?

irt.org | Knowledge Base | JavaScript | Misc | Q351 [ previous next ]

Q351 How can I detect a Mac computer and use a larger font?

You can detect a Mac using:

<script language="JavaScript"><!--
if (navigator.appVersion.indexOf('Mac') != -1)
    alert('Mac')
//--></SCRIPT>

You can combine this with a basefont tag:

<basefont
    color=color
    face=string
    id=string
    size=string
    title=string
>

to create:

<html>

<head>

<script language="JavaScript"><!--
if (navgator.appVersion.indexOf('Mac') != -1)
    document.write('<basefont size="3">')
else
    document.write('<basefont size="2">')
//--></script>

</head>

<body>
...
</body>

</html>

This has been reported to work, although not for text in table cells. Whilst you could add JavaScript code within every table cell to control the font size, this will cause problems in other browsers that choke on JavaScript code in table cells unless the entire row is output within JavaScript.

The only solution I can think of involves using Cascading Style Sheets - which will only work in Netscape Navigator 4+ and Internet Explorer 4+:

<html>

<head>

<script language="JavaScript"><!--
if (navgator.appVersion.indexOf('Mac') != -1)
    document.write('<link rel="stylesheet" href="mac.css" type="text/css">')
else
    document.write('<link rel="stylesheet" href="default.css" type="text/css">')
//--></script>

</head>

<body>
...
</body>

</html>

And then in mac.css specify larger font sizes than in default.css:

// mac.css

P, BR, UL, OL, TD, TH, LI { color: black; font-family: Arial, Helvetica, serif; font-size:large; }
// default.css

P, BR, UL, OL, TD, TH, LI { color: black; font-family: Arial, Helvetica, serif; font-size:medium; }

Feedback on 'Q351 How can I detect a Mac computer and use a larger font?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.