Why doesn't this work?

  • Thread starter jfancy-Transport Canada
  • Start date
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top