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+,Mozil la, 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="resize BodyText(2, 'n')" >+</button>
<button type="submit" onclick="resize BodyText(-2, 'n')" >-</button>
<button type="submit" onclick= "resizeBodyText (0, 'y')" >R</button>
<script type="text/javascript">
//-------------------------------------------------
var current = parseInt(getCoo kie("fontFactor "))
if (isNaN(current) )
current= 0;
resizeBodyText( current, "n")
function resizeBodyText( factor, reset)
{
if (reset=="y")
factor= (current * -1);
window.alert(cu rrent + " " + 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.f ontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].currentStyle.f ontSize)+facto r+s;
}
setCookie("font Factor", current)
}
else if (document.getEl ementsByTagName ) {
var a = document.getEle mentsByTagName( "*");
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("font Factor", current)
}
else if (document.layer s) {
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("font Factor", current)
}
else if (document.getEl ementById) {
var a = document.getEle mentById("*")
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("font Factor", current)
}
else if (document.getCo mputedStyle) {
var a = document.getCom putedStyle("*")
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("font Factor", current)
}
}
//-----------------------------------------------
function Right(str, n) {
if (n <= 0)
return "";
else if (n > String(str).len gth)
return str;
else {
var iLen = String(str).len gth;
return String(str).sub string(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.sub string(index, endstr));
}
function setCookie(name, value)
{
document.cookie = name + "=" + escape(value);
}
</script>
</body>
</html>
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+,Mozil la, 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="resize BodyText(2, 'n')" >+</button>
<button type="submit" onclick="resize BodyText(-2, 'n')" >-</button>
<button type="submit" onclick= "resizeBodyText (0, 'y')" >R</button>
<script type="text/javascript">
//-------------------------------------------------
var current = parseInt(getCoo kie("fontFactor "))
if (isNaN(current) )
current= 0;
resizeBodyText( current, "n")
function resizeBodyText( factor, reset)
{
if (reset=="y")
factor= (current * -1);
window.alert(cu rrent + " " + 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.f ontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].currentStyle.f ontSize)+facto r+s;
}
setCookie("font Factor", current)
}
else if (document.getEl ementsByTagName ) {
var a = document.getEle mentsByTagName( "*");
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("font Factor", current)
}
else if (document.layer s) {
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("font Factor", current)
}
else if (document.getEl ementById) {
var a = document.getEle mentById("*")
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("font Factor", current)
}
else if (document.getCo mputedStyle) {
var a = document.getCom putedStyle("*")
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("font Factor", current)
}
}
//-----------------------------------------------
function Right(str, n) {
if (n <= 0)
return "";
else if (n > String(str).len gth)
return str;
else {
var iLen = String(str).len gth;
return String(str).sub string(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.sub string(index, endstr));
}
function setCookie(name, value)
{
document.cookie = name + "=" + escape(value);
}
</script>
</body>
</html>
Comment