Page-Details : Size Wisely | JavaScriptSource

Page-Details : Size Wisely

Patrick Hunlock Feb 7, 2007


Use this script in your onload events to kick-start your Web pages with the right relative font size. It checks the screen resolution (not the browser size) and sets the base 'em' size accordingly.


Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: sizeWisely.js


Paste this code into the HEAD section of your HTML document.

Leave a Response


You can read [a href="!_(Tips_for_a_new_website)#quickIDX12"]the author's comments here[/a].

Lee Oct 3, 2007

It worked just fine for me. Load it after the style sheet and it should be good to go.

Lee Oct 3, 2007

I would guess most people are using an external CSS file these days, so this java script just doesn't work - I guess it can't open the CSS file to read off the text values though I would be interested if anyone managed to get it to work.

cibertrix Aug 30, 2007

re: error in IE7 -- The document.getElementsByTagName could be replaced with Also might want to make sure you call the setStartingFontSize() function onload, or as an inline script inside the BODY tag to make sure that node has been created in the DOM.[p]<body>[br /]<script type="text/javascript">[br /]setStartingFontSize();[br /]</script>[br /]...[br /]</body>

Greg Burghardt Mar 29, 2007

Hi Fletcher.[p]This script needs to run after the body tag has been created. So first you need to make sure your web page has a body tag, then your script needs to be either inside it or called in an onload event. body onload='setStartingFontSize()'[p]That should clear up the problem you discovered.

Patrick Feb 20, 2007