J
jfancy-Transport Canada
Hi, I have a js file connected to a html file and it will not work. It
increases and decreases font size by its relative size. The buttons
won't execute. Any suggestions??
JS FILE:
-------------------------------------
var current = 0
var basesize = parseFloat(getCookie("fontFactor"))
resizeBodyText(basesize, "n")
function resizeBodyText(factor, reset)
{
if (window.getComputedStyle)
{
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
}
current += factor;
var s, an, au, i=a.length;
while ( --i ){
s=a.getComputedStyle.fontSize;
an = parseFloat(s); // Get the number part
au = s.replace(an,''); // Get the units
a.style.fontSize = an + factor + au;
}
setCookie("fontFactor", current)
}
else if (window.currentstyle)
{
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
}
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)
}
-------------------------------------------------------------------
HTML FILE:
------------------------------------------------------------------
<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>
--------------FEEL FREE TO HELP!!----------------------------------
Justin
increases and decreases font size by its relative size. The buttons
won't execute. Any suggestions??
JS FILE:
-------------------------------------
var current = 0
var basesize = parseFloat(getCookie("fontFactor"))
resizeBodyText(basesize, "n")
function resizeBodyText(factor, reset)
{
if (window.getComputedStyle)
{
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
}
current += factor;
var s, an, au, i=a.length;
while ( --i ){
s=a.getComputedStyle.fontSize;
an = parseFloat(s); // Get the number part
au = s.replace(an,''); // Get the units
a.style.fontSize = an + factor + au;
}
setCookie("fontFactor", current)
}
else if (window.currentstyle)
{
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
}
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)
}
-------------------------------------------------------------------
HTML FILE:
------------------------------------------------------------------
<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>
--------------FEEL FREE TO HELP!!----------------------------------
Justin