Javascript crashes

Questions about programming languages and debugging
Post Reply
fanman
Newbie
Newbie
Posts: 5
Joined: 02 Dec 2010, 14:38
13

Javascript crashes

Post by fanman »

Hi guys. I made a javascript today and since im not so good at it i could need some help.
When i start it i just crashes. I should open many popups when you load the page.

Code: Select all

<html>
	<head>
		<title></title>
		<script type="text/javascript">
			i=0;
			while (i<=5)
			function poponload()
				{
					testwindow = window.open("", "mywindow", "location=1,status=1,scrollbars=1,width=100,height=100");
					testwindow.moveTo(0, 0);
				}
		</script>
	</head>
	<body onload="javascript: poponload()">

	</body>
</html>
Thank you!

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Javascript crashes

Post by ayu »

Try this instead, notice the difference

You need to increment the "i" variable, and also the while loop is more suitable to be inside the function, as the function call wont call the loop.
Actually, the loop will just be on the page when it loads, and keep looping forever.

Code: Select all

<html>
   <head>
      <title></title>
      <script type="text/javascript">
         
         function poponload()
            {
		i=0;
         	while (i<=5)
		{
               testwindow = window.open("", "mywindow", "location=1,status=1,scrollbars=1,width=100,height=100");
               testwindow.moveTo(0, 0);
		++i;
		}
            }
      </script>
   </head>
   <body onload="javascript: poponload()">

   </body>
</html>
"The best place to hide a tree, is in a forest"

fanman
Newbie
Newbie
Posts: 5
Joined: 02 Dec 2010, 14:38
13

Re: Javascript crashes

Post by fanman »

Thank you very much :D

Post Reply