Javascript Puzzle Anyone?

0 views
Skip to first unread message

jfancy-Transport Canada

unread,
Jun 8, 2005, 9:03:08 AM6/8/05
to teen-pro...@googlegroups.com
Hi everyone,

Just wanted to post this on here to see what you all could come up
with. I am creating a Font Sizer and it has to be compatible with
NN4+,IE4+,Mozilla, And Opera. I have it working fine in all IE
versions, but it doesn't work at all in the other browsers. Remember,
this is a relative font sizer. Maybe i can use percentages? Anyone have
any examples? I can find lots of examples of setting font sizes so that
EVERYTHING on the page changes ot the same font size, but i don't want
that. I need something that will take the relative sont size. I have
alerts set up to let me know what's happening. Here's the code:

<html>
<head>

</head>
<body>
<h1>Hello there</h1>
<h2>Test</h2>
anything.
<br><br>
<button type="submit" onclick="resizeBodyText(2, 'n')" >+</button>
<button type="submit" onclick="resizeBodyText(-2, 'n')" >-</button>
<button type="submit" onclick= "resizeBodyText(0, 'y')" >R</button>


<script type="text/javascript">
//-------------------------------------------------


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)
//------------------------------------------------
if (document.all) {
var a = document.all;
var s = '';
current += factor;
var test = "IE!"

if (current < 0)
current = 0;

else
for (var i = a.length-1; i >0;i--)
{
s=a[i].currentStyle.fontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].currentStyle.fontSize)+factor+s;
}
setCookie("fontFactor", current)
}
else if (document.getElementsByTagName) {
var a = document.getElementsByTagName("*");
var s = '';
current += factor;
var test = "Netscape 6+!"
if (current < 0)
current = 0;
else
for (var i = a.length-1; i >0;i--)
{
s=a[i].style.fontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].style.fontSize)+factor+s;
}
setCookie("fontFactor", current)
}
else if (document.layers) {
var a = document.layers("*");
var s = '';
current += factor;
var test = "Netscape 6+!"
if (current < 0)
current = 0;
else
for (var i = a.length-1; i >0;i--)
{
s=a[i].style.fontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].style.fontSize)+factor+s;
}
setCookie("fontFactor", current)
}
else if (document.getElementById) {
var a = document.getElementById("*")
var s = '';
current += factor;
var test = "Opera 5!"
if (current < 0)
current = 0;
else
for (var i = a.length-1; i >0;i--)
{
s=a[i].style.fontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].style.fontSize)+factor+s;
}
setCookie("fontFactor", current)
}
else if (document.getComputedStyle) {
var a = document.getComputedStyle("*")
var s = '';
var test = "Mozilla!"
current += factor;
if (current < 0)
current = 0;
else
for (var i = a.length-1; i >0;i--)
{
s=a[i].style.fontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].style.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);
}

</script>

</body>
</html>

Reply all
Reply to author
Forward
0 new messages