PDA

View Full Version : Script doesn't work with firefox


drukje
10-27-2005, 01:53 PM
Hello,

I made a script that gives alerts when something succesfully added to or removed from a database. The alert works well with IE but Firefox doesn't show anything. Can anybody help me?

The script:

<!-- adjust style= to position messages -->

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
// texts:
// Your messages wich may contain regular html tags but
// must at least contain: [ <font color='{COLOR}'> ]
// Use single quotes [ ' ] in your html only. If you need
// a double quote in the message itself use an escape
// sign like this: [ \" ] (not including the brackets)

var texts = new Array(
"<font size='+0' color='{COLOR}' face='Arial'><strong><?PHP
include("meldingen.php");
?>
</strong></font>",
"<font size='+0' color='{COLOR}' face='Arial'><strong></strong></font>");
var bgcolor = "#000000"; // background color, must be valid browser hex color (not color names)
var fcolor = "#FF8000"; // foreground or font color
var steps = 20; // number of steps to fade
var show = 5000; // milliseconds to display message
var sleep = 30; // milliseconds to pause inbetween messages
var loop = false; // true = continue to display messages, false = stop at last message

// Do Not Edit Below This Line
var colors = new Array(steps);
getFadeColors(bgcolor,fcolor,colors);
var color = 0;
var text = 0;
var step = 1;

// fade: magic fader function
function fade()
{
// insert fader color into message
var text_out = texts[text].replace("{COLOR}", colors[color]); // texts should be defined in user script, e.g.: var texts = new Array("<font color='{COLOR}' sized='+3' face='Arial'>howdy</font>");

// actually write message to document
if (document.all) fader.innerHTML = text_out; // document.all = IE only
if (document.layers) { document.fader.document.write(text_out); document.fader.document.close(); } // document.layers = Netscape only

// select next fader color
color += step;

// completely faded in?
if (color >= colors.length-1)
{
step = -1; // traverse colors array backward to fade out

// stop at last message if loop=false
if (!loop && text >= texts.length-1) return; // loop should be defined in user script, e.g.: var loop=true;
}

// completely faded out?
if (color == 0)
{
step = 1; // traverse colors array forward to fade in again

// select next message
text += 1;
if (text == texts.length) text = 0; // loop back to first message
}

// subtle timing logic...
setTimeout("fade()", (color == colors.length-2 && step == -1) ? show : ((color == 1 && step == 1) ? sleep : 50)); // sleep and show should be defined in user script, e.g.: var sleep=30; var show=500;
}
// getFadeColors: fills Colors (predefined Array)
// with color hex strings fading from ColorA to ColorB

// note: Colors.length equals the number of steps to fade
function getFadeColors(ColorA, ColorB, Colors)
{
len = Colors.length;

// strip '#' signs if present
if (ColorA.charAt(0)=='#') ColorA = ColorA.substring(1);
if (ColorB.charAt(0)=='#') ColorB = ColorB.substring(1);

// substract rgb compents from hex string
var r = HexToInt(ColorA.substring(0,2));
var g = HexToInt(ColorA.substring(2,4));
var b = HexToInt(ColorA.substring(4,6));
var r2 = HexToInt(ColorB.substring(0,2));
var g2 = HexToInt(ColorB.substring(2,4));
var b2 = HexToInt(ColorB.substring(4,6));

// calculate size of step for each color component
var rStep = Math.round((r2 - r) / len);
var gStep = Math.round((g2 - g) / len);
var bStep = Math.round((b2 - b) / len);

// fill Colors array with fader colors
for (i = 0; i < len-1; i++)
{
Colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
r += rStep;
g += gStep;
b += bStep;
}
Colors[len-1] = ColorB; // make sure we finish exactly at ColorB
}

// IntToHex: converts integers between 0-255 into a two digit hex string.
function IntToHex(n)
{
var result = n.toString(16);
if (result.length==1) result = "0"+result;
return result;
}

// HexToInt: converts two digit hex strings into integer.
function HexToInt(hex)
{
return parseInt(hex, 16);
}

// body tag must include: onload="fade()" bgcolor="#000000" where bgcolor equals bgcolor in javascript above
// End -->
</script>


And in the body
<script>fade()</script>

How can I get that or something like this working in other browser.

drukje
10-27-2005, 02:18 PM
And the include file contains (it's dutch):


if($_GET["melding"]==1)
{
echo("Gegevens succesvol toegevoegd");
}

if($_GET["melding"]==2)
{
echo("Gegevens succesvol verwijderd");
}

if($_GET["melding"]==3)
{
echo("Wijzigingen succesvol opgeslagen");
}

if($_GET["melding"]==4)
{
echo("Uw login gegevens waren niet juist");
}

glenngv
10-27-2005, 02:20 PM
Change these lines:

if (document.all) fader.innerHTML = text_out; // document.all = IE only
if (document.layers) { document.fader.document.write(text_out); document.fader.document.close(); } // document.layers = Netscape only

to:

if (document.getElementById) document.getElementById("fader").innerHTML = text_out; //modern browsers (IE5+, Firefox, etc.)
else if (document.all) document.all["fader"].innerHTML = text_out; // document.all = IE4+
else if (document.layers) { document.layers["fader"].document.write(text_out); document.layers["fader"].document.close(); } // document.layers = Netscape 4 only
Make sure that the target tag has an id of "fader".

drukje
10-27-2005, 02:44 PM
thanx mate,

I past the code over the old one and it worked. What do you mean with target tag?

felgall
10-27-2005, 10:26 PM
THe target tag is the one that you want the effect to apply to.

Note that the script is extremely old (was written for version 4 borwsers) and most of the code that it uses is deprecated (which means it probably wont work in the version 9 browsers that are about to be released). There are much better ways to achieve the same effect by using Javascript to manipulate stylesheets.