J
jfancy-Transport Canada
Hi, I am making a js file that increases font sizes by its relative
size. It works fine as all one file with the script in the html file
but when i go to put the js in a seperate file and reference it as a
source file, it doesn't work properly. What happens is that when i go
to increase the font size, it goes lower(the first time), but the next
time it increase and increases, and decreases, which is fine. But
whatever happens, it sets it to a different start value, which is
wrong.
here's the code for the html file:
-------------------------------------------------------------------
<html>
<head>
<SCRIPT TYPE="text/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="reset" onclick= "resizeBodyText(0, 'y')">
</body>
</html>
------------------------------------------------------------------
And here's the code for the js file:
-------------------------------------------------------------------
var current = parseInt(getCookie("fontFactor"))
if (isNaN(current))
current= 0;
resizeBodyText(current, "n")
function resizeBodyText(factor, reset)
{
if (reset=="y")
factor= (current * -1);
window.alert(current + " " + factor)
//------------------------------------------------
var a = document.all;
var s = '';
current += factor;
if (current < 0)
current = 0;
else
for (var i = a.length-1; i >0;i--)
{
s=a.currentStyle.fontSize+'';
s=Right(s,2);
a.style.fontSize = parseInt(a.currentStyle.fontSize)+factor+s;
}
setCookie("fontFactor", current)
}
//-----------------------------------------------
function Right(str, n) {
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}
//-------------------------------------------------
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);
}
size. It works fine as all one file with the script in the html file
but when i go to put the js in a seperate file and reference it as a
source file, it doesn't work properly. What happens is that when i go
to increase the font size, it goes lower(the first time), but the next
time it increase and increases, and decreases, which is fine. But
whatever happens, it sets it to a different start value, which is
wrong.
here's the code for the html file:
-------------------------------------------------------------------
<html>
<head>
<SCRIPT TYPE="text/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="reset" onclick= "resizeBodyText(0, 'y')">
</body>
</html>
------------------------------------------------------------------
And here's the code for the js file:
-------------------------------------------------------------------
var current = parseInt(getCookie("fontFactor"))
if (isNaN(current))
current= 0;
resizeBodyText(current, "n")
function resizeBodyText(factor, reset)
{
if (reset=="y")
factor= (current * -1);
window.alert(current + " " + factor)
//------------------------------------------------
var a = document.all;
var s = '';
current += factor;
if (current < 0)
current = 0;
else
for (var i = a.length-1; i >0;i--)
{
s=a.currentStyle.fontSize+'';
s=Right(s,2);
a.style.fontSize = parseInt(a.currentStyle.fontSize)+factor+s;
}
setCookie("fontFactor", current)
}
//-----------------------------------------------
function Right(str, n) {
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}
//-------------------------------------------------
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);
}