Jump to content

try to place script in onLoad...


schabluk

Recommended Posts

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

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

[/code]

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

[code]
<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();">
[/code]

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

[code]
<BODY onLoad="text= new Array('ala');alert(text);">
[/code]
works for me..
Link to comment
Share on other sites

Hi there,,

Try that,,... that one works:
[code]<html>
<head>
<title> New Document </title>
</head>
<body onLoad="javascript:function SNOW_Weather(){alert('hmm,,');};SNOW_Weather();">
</body>
</html>[/code]
but that one doesn't work:
[code]<html>
<head>
<title> New Document </title>
</head>
<body onLoad="javascript:function SNOW_Weather(){alert('hmm,,');};SNOW_Weather();setTimeout('SNOW_Weather()',10);">
</body>
</html>[/code]
& Firefox reports:
>Erreur : SNOW_Weather is not defined<
Same error for:
[code]
<html>
<head>
<title> New Document </title>
</head>
<body onLoad="javascript:function SNOW_Weather(){alert('hmm,,');};SNOW_Weather();">
<script>
SNOW_Weather();
</script>
</body>
</html>
[/code]
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,,
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.