J
jfancy-Transport Canada
I have this code here that reads in a javascript file and increases or
decreases font by its relative size (same thing as View, Text Size,
Large, small, etc.) I am developing this for Transport Canada and I
need some help. Here is my code. I need it to be compatible with IE,
Mozilla, Netscape and Opera. Most versions of these browsers has to be
compatible. If you could help me out the least bit would greatful.
Here's the code:
HTML:
<html>
<head>
<script language="javascript" src="textsize2.js"> </script>
</head>
<body>
<h1>Hello there</h1>
<h2>Test</h2>
anything.
<input type="button" onclick="resizeBodyText(+2, 'n')" value="Font +" >
<input type="button" onclick="resizeBodyText(-2, 'n')" value="Font -" >
<input type="button" onclick= "resizeBodyText(0, 'y')" value="Reset">
<input type="button" onclick= "clearCookie()" value="Clear Cookie">
</body>
</html>
-------------------------------------------------------------------
JAVASCRIPT FILE:
var current = 0
var basesize = parseFloat(getCookie("fontFactor"))
window.onload=function(){
resizeBodyText(basesize, "n")
}
function resizeBodyText(factor, reset){
if (reset=="y")
factor = (current * -1);
if (document.getElementsByTagName){
var a = document.getElementsByTagName('*');
} else if (document.all){
var a = document.all;
} else {
return; // No point in continuing
}
// exit if currentStyle or style not supported
if (!a[0].currentStyle || !a[0].style ) return;
current += factor;
var s, an, au, i=a.length;
while ( --i ){
s=a.currentStyle.fontSize;
an = parseFloat(s); // Get the number part
au = s.replace(an,''); // Get the units
a.style.fontSize = an + factor + au;
}
setCookie("fontFactor", current)
}
function getCookie(name){
var dc = document.cookie;
var index = dc.indexOf(name + "=");
if (index == -1) return null;
index = dc.indexOf("=", index) + 1; // first character
var endstr = dc.indexOf(";", index);
if (endstr == -1) endstr = dc.length; // last character
return unescape(dc.substring(index, endstr));
}
function setCookie(name, value){
document.cookie= name + "=" + escape(value);
}
function clearCookie(){
setCookie("fontFactor", 0)
}
decreases font by its relative size (same thing as View, Text Size,
Large, small, etc.) I am developing this for Transport Canada and I
need some help. Here is my code. I need it to be compatible with IE,
Mozilla, Netscape and Opera. Most versions of these browsers has to be
compatible. If you could help me out the least bit would greatful.
Here's the code:
HTML:
<html>
<head>
<script language="javascript" src="textsize2.js"> </script>
</head>
<body>
<h1>Hello there</h1>
<h2>Test</h2>
anything.
<input type="button" onclick="resizeBodyText(+2, 'n')" value="Font +" >
<input type="button" onclick="resizeBodyText(-2, 'n')" value="Font -" >
<input type="button" onclick= "resizeBodyText(0, 'y')" value="Reset">
<input type="button" onclick= "clearCookie()" value="Clear Cookie">
</body>
</html>
-------------------------------------------------------------------
JAVASCRIPT FILE:
var current = 0
var basesize = parseFloat(getCookie("fontFactor"))
window.onload=function(){
resizeBodyText(basesize, "n")
}
function resizeBodyText(factor, reset){
if (reset=="y")
factor = (current * -1);
if (document.getElementsByTagName){
var a = document.getElementsByTagName('*');
} else if (document.all){
var a = document.all;
} else {
return; // No point in continuing
}
// exit if currentStyle or style not supported
if (!a[0].currentStyle || !a[0].style ) return;
current += factor;
var s, an, au, i=a.length;
while ( --i ){
s=a.currentStyle.fontSize;
an = parseFloat(s); // Get the number part
au = s.replace(an,''); // Get the units
a.style.fontSize = an + factor + au;
}
setCookie("fontFactor", current)
}
function getCookie(name){
var dc = document.cookie;
var index = dc.indexOf(name + "=");
if (index == -1) return null;
index = dc.indexOf("=", index) + 1; // first character
var endstr = dc.indexOf(";", index);
if (endstr == -1) endstr = dc.length; // last character
return unescape(dc.substring(index, endstr));
}
function setCookie(name, value){
document.cookie= name + "=" + escape(value);
}
function clearCookie(){
setCookie("fontFactor", 0)
}