Jump to content


Photo

try to place script in onLoad...


  • Please log in to reply
1 reply to this topic

#1 schabluk

schabluk
  • Members
  • Pip
  • Newbie
  • 1 posts
  • LocationPoland, Warsav

Posted 15 May 2006 - 01:21 PM

Hi folks and sorry for my bad English ;]

i have a problem with script I want to run from onLoad HTML attribute.

take a look at this code...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<script LANGUAGE="JavaScript">
<!--
SNOW_dx = new Array();SNOW_xp = new Array();SNOW_yp = new Array();SNOW_am = new Array();SNOW_stx = new Array();SNOW_sty = new Array();for (i = 0; i < 20; ++ i){SNOW_dx[i] = 0; SNOW_xp[i] = Math.random()*(650-50);SNOW_yp[i] = 36 + Math.random()*650;SNOW_am[i] = Math.random()*20;SNOW_stx[i] = 0.02 + Math.random()/10;SNOW_sty[i] = 0.7 + Math.random();if (i == 0) makeFlake(i);else makeFlake(i);}function makeFlake(i){var daBody = document.getElementsByTagName('body')[0];hcXdiv = document.createElement('div');hcXimg = document.createElement('img');hcXdiv.appendChild(hcXimg);daBody.appendChild(hcXdiv);hcXdiv.setAttribute('id', 'SNOW_flake' + i);hcXdiv.style.position='absolute';hcXimg.setAttribute('src', 'http://localhost/icons/folder.gif');};function SNOW_Weather(){for (i = 0; i < 20; ++ i){SNOW_yp[i] += SNOW_sty[i];if (SNOW_yp[i] > 650-50){SNOW_xp[i] = Math.random()*(650-SNOW_am[i]-30);SNOW_yp[i] = 0;SNOW_stx[i] = 0.02 + Math.random()/10;SNOW_sty[i] = 0.7 + Math.random();}SNOW_dx[i] +=SNOW_stx[i];document.getElementById('SNOW_flake'+i).style.top=SNOW_yp[i]+'px';document.getElementById('SNOW_flake'+i).style.left=SNOW_xp[i] + SNOW_am[i]*Math.sin(SNOW_dx[i])+'px';}setTimeout('SNOW_Weather()',10);}
//-->
</SCRIPT>
<img src="http://www.google.pl/images/hp0.gif" onLoad="javascript:SNOW_Weather();">
</BODY>
</HTML>


it works fine, but if I want to put variables and functions declaration into onLoad attribute, \
it crash... :

<img src="http://www.google.pl/images/hp0.gif" onLoad="javascript:SNOW_dx = new Array();SNOW_xp = new Array();SNOW_yp = new Array();SNOW_am = new Array();SNOW_stx = new Array();SNOW_sty = new Array();for (i = 0; i < 20; ++ i){SNOW_dx[i] = 0; SNOW_xp[i] = Math.random()*(650-50);SNOW_yp[i] = 36 + Math.random()*650;SNOW_am[i] = Math.random()*20;SNOW_stx[i] = 0.02 + Math.random()/10;SNOW_sty[i] = 0.7 + Math.random();if (i == 0) makeFlake(i);else makeFlake(i);}function makeFlake(i){var daBody = document.getElementsByTagName('body')[0];hcXdiv = document.createElement('div');hcXimg = document.createElement('img');hcXdiv.appendChild(hcXimg);daBody.appendChild(hcXdiv);hcXdiv.setAttribute('id', 'SNOW_flake' + i);hcXdiv.style.position='absolute';hcXimg.setAttribute('src', 'http://localhost/icons/folder.gif');};function SNOW_Weather(){for (i = 0; i < 20; ++ i){SNOW_yp[i] += SNOW_sty[i];if (SNOW_yp[i] > 650-50){SNOW_xp[i] = Math.random()*(650-SNOW_am[i]-30);SNOW_yp[i] = 0;SNOW_stx[i] = 0.02 + Math.random()/10;SNOW_sty[i] = 0.7 + Math.random();}SNOW_dx[i] +=SNOW_stx[i];document.getElementById('SNOW_flake'+i).style.top=SNOW_yp[i]+'px';document.getElementById('SNOW_flake'+i).style.left=SNOW_xp[i] + SNOW_am[i]*Math.sin(SNOW_dx[i])+'px';}setTimeout('SNOW_Weather()',10);}SNOW_Weather();">

I'm out of idea... simple scripts like

<BODY onLoad="text= new Array('ala');alert(text);">
works for me..


#2 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 18 May 2006 - 01:06 AM

Hi there,,

Try that,,... that one works:
<html>
<head>
<title> New Document </title>
</head>
<body onLoad="javascript:function SNOW_Weather(){alert('hmm,,');};SNOW_Weather();">
</body>
</html>
but that one doesn't work:
<html>
<head>
<title> New Document </title>
</head>
<body onLoad="javascript:function SNOW_Weather(){alert('hmm,,');};SNOW_Weather();setTimeout('SNOW_Weather()',10);">
</body>
</html>
& Firefox reports:
>Erreur : SNOW_Weather is not defined<
Same error for:
<html>
<head>
<title> New Document </title>
</head>
<body onLoad="javascript:function SNOW_Weather(){alert('hmm,,');};SNOW_Weather();">
<script>
SNOW_Weather();
</script>
</body>
</html>
It means the function is defined just for the loading part,... not for the rest of the time,,... I suppose,...

Btw,,... I don't see the usefull of making such complicated things,... as your first code works fine,... :)

Hoping it helps,,

l8tr,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users