Javascript Puzzle Anyone??

F

Fancy Pants

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.currentStyle.fontSize+'­';
s=Right(s,2);
a.style.fontSize = parseInt(a.currentStyle.fon­tSize)+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.style.fontSize+'';
s=Right(s,2);
a.style.fontSize = parseInt(a.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.style.fontSize+'';
s=Right(s,2);
a.style.fontSize = parseInt(a.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.style.fontSize+'';
s=Right(s,2);
a.style.fontSize = parseInt(a.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.style.fontSize+'';
s=Right(s,2);
a.style.fontSize = parseInt(a.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>
 
S

Stephen Chalmers

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:
----------------------

You have been told elsewhere:
http://www.developersdex.com/asp/[email protected].
com%3E
how to do this, namely by using relative font sizes for all elements and just changing the size of the body
font, which resizes all others automatically.
If you cannot act upon advice there's no point in continually asking the same question, or being a student for
that matter.

Here is the minimal modification to your original code.
It cannot work on NN4.
Let's hope it never gets used...

<html>
<head>
</head>

<body style={font-size:12pt}>
<h1 style={font-size:1.2em}>Hello there</h1>
<h2 style={font-size:1.1em}>Test</h2>
anything.

<script type="text/javascript">
if(document.body && (document.getElementById || document.all) )
document.write("<form><input type='button' onclick=\"resizeBodyText(2, 'n')\" value='2'><input type='button'
onclick=\"resizeBodyText(-2, 'n')\" value='-2' ><input type='button' onclick= \"resizeBodyText(0, 'y')\"
value='0'></form>");

var current = parseInt(getCookie("fontFactor"))
if (isNaN(current))
current= 0;

resizeBodyText(current, "n")

function resizeBodyText(factor, reset)
{
if (reset=="y")
factor= (current * -1);

var a=null;

if (current < 0)
current = 0;
else
if( typeof document.body.currentStyle != 'undefined' )
{
s=document.body.currentStyle.fontSize+'';
s=Right(s,2);
document.body.style.fontSize= parseInt(document.body.currentStyle.fontSize,10)+factor+s;
}
else
if( typeof document.body.style != 'undefined')
{
s=document.body.style.fontSize+'';
s=Right(s,2);
document.body.style.fontSize = parseInt(document.body.style.fontSize)+factor+s;
}

setCookie("fontFactor", current)
}

file://-----------------------------------------------
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);
}
}
file://-------------------------------------------------
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>
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top