Forum Moderators: open

Message Too Old, No Replies

Issues with FireFox JavaScript

Need help fast

         

goatboynsac

7:38 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



I have a little Script i use to make an image float around the page. It works in IE but not Firefox. Can someone tell me why? The code is below.

<SCRIPT language="JavaScript1.2">
var T;
var cursorpath;
if(Math.random() > 0.5)
{
cursorpath="images/newproductpic.gif "; //just replace "../images/saddam.jpg " with the name of your picture
}
else
{
cursorpath="images/newproductpic.gif"; //just replace "good.gif" with the name of your picture

}

if (document.layers)
{document.write("<LAYER NAME='PoInTeRs' LEFT=10 TOP=10><img src='"+cursorpath+"' width=115 height=137 onclick=\"stopEffect();\"></LAYER>")}
else if (document.all){document.write("<div id='pOiNtErS' style='position:absolute;top:10px;left:10px;width:115px;height:137px;z-index:50'><img src='"+cursorpath+"' width=225 height=134 onclick=\"stopEffect();\"></div>")}

count=-1;
move=1;

function Curve(){
abc=new Array(0,1,1,1,2,3,4,0,6,-1,-1,-1,-2,-3,-4,0,-6)
for (i=0; i < abc.length; i++)
{var C=Math.round(Math.random()*[i])}
howbend=abc[C];
setTimeout('Curve()',1900);
return howbend;
}
ypos=300;
xpos=250;

degree = 1;
function MoveRandom(){
PathBend=degree+=howbend;//ok!
y = 4*Math.tan(PathBend*Math.PI/1);
x = 6*Math.cos(PathBend*Math.PI/1);
if (document.layers){
ypos+=y;
xpos+=x;
document.PoInTeRs.top=ypos+window.pageYOffset;
document.PoInTeRs.left=xpos+window.pageXOffset;
}
else if (document.all){
ypos+=y;
xpos+=x;
document.all.pOiNtErS.style.top=ypos+document.body.scrollTop;
document.all.pOiNtErS.style.left=xpos+document.body.scrollLeft;
}
T=setTimeout('MoveRandom()',50);
}
function edges(){
if (document.layers){
if (document.PoInTeRs.left >= window.innerWidth-40+window.pageXOffset)degree=Math.round(Math.random()*45+157.5);
if (document.PoInTeRs.top >= window.innerHeight-30+window.pageYOffset)degree=Math.round(Math.random()*45-112.5);
if (document.PoInTeRs.top <= 2+window.pageYOffset) degree = Math.round(Math.random()*45+67.5);//OK!
if (document.PoInTeRs.left <= 2+window.pageXOffset) degree = Math.round(Math.random()*45-22.5);//OK!
}
else if (document.all)
{
if (document.all.pOiNtErS.style.pixelLeft >= document.body.offsetWidth-645+document.body.scrollLeft)degree=Math.round(Math.random()*45+157.5);
if (document.all.pOiNtErS.style.pixelTop >= document.body.offsetHeight-35+document.body.scrollTop)degree=Math.round(Math.random()*45-112.5);
if (document.all.pOiNtErS.style.pixelTop <= 2+document.body.scrollTop) degree = Math.round(Math.random()*45+67.5);//OK!
if (document.all.pOiNtErS.style.pixelLeft <= 2+document.body.scrollLeft+250) degree = Math.round(Math.random()*45-22.5);//OK!
}
setTimeout('edges()',100);
}
function starteffect(){
Curve();
MoveRandom();// onUnload="opener.gO()"
edges();
}

// Stop the effect and hide the container
function stopEffect() {
clearTimeout(T);
if (document.layers) {
document.layers.PoInTeRs.style.visibility = "hidden";
} else {
document.getElementById("pOiNtErS").style.visibility = "hidden";
}
}

if (document.all¦¦document.layers)
window.onload=starteffect
</script>

orion_rus

10:24 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



try to change
LAYER to div
may be it's fault Firefox!

lZakl

12:52 am on Mar 10, 2005 (gmt 0)

10+ Year Member



document.all isn't supported by Firefox..

document.all is a Microsoft specific code that isn't a W3C DOM standard.

Frirfox WILL however ruturn a true or a false. For example:

if (document.all)
{
alert('true')
}

else
{
alert('false');
}

So you can test for it, but you can't "use" it. Instead use:

document.getElementById('someid').innerHTML

goatboynsac

3:52 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



Im still having an issue with it. I have changed all the spots that you said, after that didnt work, i changed the document.layers also. But it still refuses to work in anything but IE.

goatboynsac

3:54 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



Also what do i do about document.all? Just put "document.getElementById('PoInTeRs')" or would i put "document.getElementById". And the same with document.layers.

goatboynsac

4:19 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



Here is the cleaned up code, But still no luck

<SCRIPT language="JavaScript1.2">
var T;
var cursorpath;
if(Math.random() > 0.5)
{
cursorpath="images/newproductpic.gif "; //just replace "../images/saddam.jpg " with the name of your picture
}
else
{
cursorpath="images/newproductpic.gif"; //just replace "good.gif" with the name of your picture

}

{document.write("<div id='pOiNtErS' style='position:absolute;top:10px;left:10px;width:115px;height:137px;z-index:50'><img src='"+cursorpath+"' width=225 height=134 onclick=\"stopEffect();\"></div>")}

count=-1;
move=1;

function Curve(){
abc=new Array(0,1,1,1,2,3,4,0,6,-1,-1,-1,-2,-3,-4,0,-6)
for (i=0; i < abc.length; i++)
{var C=Math.round(Math.random()*[i])}
howbend=abc[C];
setTimeout('Curve()',1900);
return howbend;
}
ypos=300;
xpos=250;

degree = 1;
function MoveRandom(){
PathBend=degree+=howbend;//ok!
y = 4*Math.tan(PathBend*Math.PI/1);
x = 6*Math.cos(PathBend*Math.PI/1);
if (document.getElementById){
ypos+=y;
xpos+=x;
document.getElementById('PoInTeRs').style.top=ypos+document.body.scrollTop;
document.getElementById('PoInTeRs').style.left=xpos+document.body.scrollLeft;
}
T=setTimeout('MoveRandom()',50);
}
function edges(){
if (document.getElementById)
{
if (document.getElementById('PoInTeRs').style.pixelLeft >= document.body.offsetWidth-645+document.body.scrollLeft)degree=Math.round(Math.random()*45+157.5);
if (document.getElementById('PoInTeRs').style.pixelTop >= document.body.offsetHeight-35+document.body.scrollTop)degree=Math.round(Math.random()*45-112.5);
if (document.getElementById('PoInTeRs').style.pixelTop <= 2+document.body.scrollTop) degree = Math.round(Math.random()*45+67.5);//OK!
if (document.getElementById('PoInTeRs').style.pixelLeft <= 2+document.body.scrollLeft+250) degree = Math.round(Math.random()*45-22.5);//OK!
}
setTimeout('edges()',100);
}
function starteffect(){
Curve();
MoveRandom();// onUnload="opener.gO()"
edges();
}

// Stop the effect and hide the container
function stopEffect() {
clearTimeout(T);
document.getElementById('PoInTeRs').style.visibility = "hidden";

}

if (document.getElementById¦¦document.layers)
window.onload=starteffect

</script>

goatboynsac

11:23 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



still need help here

habbahabba

12:01 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Hi!
I saw that you had a bunch of questions regarding firefox and javascript. The thing is that you have very old code in your scripts and instead of looking through every problem you have I suggest you study the W3C DOM instead on IE because W3C is a STANDARD.

Good resources are ofcourse w3c.org but there is also an excelent page [quirksmode.org...] that goes through how you should write good JS code. It also sortes out differences between browsers.

I also would like to point out that now a days you always have to specify the unit of measurement. Like PX. Donät write just top: 30. You have to write top: 30px;

And also learn to terminate all JS rows with semicolon ; It is good pratice.

/Henke

goatboynsac

12:34 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Thank you for your help.