Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Multiple Windows

Status
Not open for further replies.

light742

Technical User
Aug 9, 2010
15
0
0
US
Hello:

Hello Everybody:

I have a JavaScript that allows you to open 5 additional windows when you click on the button. It works properly when using Mozilla, but when you use IE7, only 1 window pops
up not 5. I would appreciate the help!!!

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]


<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] lang="en" xml:lang="en">


<head>


<title>Open Multiple Windows</title>


<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />


<meta http-equiv="Content-Language" content="en-us" />

<meta name="description" content="Wealthy List" />
<meta name="keywords" content="Wealthy List" />



<!-- the absolute pathname of this file is:            -->

<!-- C:\MISCSUP2_10_17_8\MISCSUP2\Javascript_Demystified_Download_Working\ -->
<!-- Ch_9_Page192.html -->
<!-- NOTE that the Authors download files have errors in that he forgot to -->
<!-- follow the format for making comments.  He forgot to put in the second dash -->
<!-- for the left comment format -->


<!-- this file was created on Saturday, 10/30/10:                                  -->
<!-- this file was updated on Saturday, 10/30/10:                                  -->
<!-- Note that this opens up 5 new windows using Mozilla, but only opens 1 window in IE7 -->

<script language="Javascript" type="text/javascript">
         
          
         
               <!--
function Launch() {
         for (i=0; i < 5;i++)
         { 
            Win = window.open('', 'win'+i, 'width=50,height=50')
         }
      }


               -->

      </script>


</head>

   <body>



      <form action="[URL unfurl="true"]http://www.jimkeogh.com"[/URL] method="post">

         <p>

           <input name="WindowsGoneWild" 

            value="Windows Gone Wild" type="button" 

            onclick="Launch()"/>

         </p>

     </form>



     <noscript>
         <h1> JavaScript Required</h1>
      </noscript>

   </body>


</html>
 
Have you tried using setTimeout with a small delay, something like 10 or 50? It might do the job.

I'm curious... why do you want to open 5 blank windows anyway?

Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
I'm trying to open up 5 windows at a time because I am learning JavaScript from a book and that is one of the exercises. I still can't get it to work and would appreciate the help.
 
2 things. IE will block the popups unless you specifically set it to allow them. You should be getting a warning t the top of the browse saying as much.

Furthermore, IE also has problems with opening so many windows at a time. Dan's suggestion of a timeout should work.

Code:
function Launch() {
         for (i=0; i < 5;i++)
         {
            setTimeout(Win = window.open('', 'win'+i, 'width=50,height=50'),[red]50[/red]);
         }
      }

The red number is the amount of time to wait before executing the window.open command.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
That doesn't work. Now I get an error message that states
"Error: Invalid Argument"

The complete code is below:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
   <title>Open Multiple Windows</title>
   <script language="Javascript" type="text/javascript">
   <!--
      function Launch() { 
         var Win = new Array();
         for (i=0; i < 5;i++)
         {
            setTimeout(Win = window.open('', 'win'+i, 'width=50,height=50'),50);
         }
       } 
--> 

</script>

</head>
   <body>
      <form action="[URL unfurl="true"]http://www.jimkeogh.com"[/URL] method="post">
         <p>
<input name="WindowsGoneWild" value="Windows Gone Wild" type="button" onclick="Launch()"/>
         </p>
     </form>
   </body>
</html>
 
I just copied your code above, and ran it. Works for me, no errors. Once allowed by IE, all 5 windows open.

5wins.jpg


Which likely means there's something else you aren't showing us.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thank you for posting the screenshot. I noticed that the URL in your screenshot is whereas I just opened the IE7 browser and opened the file. I was only able to get 1 window to pop-up.
 
The address makes no difference. I can open it through the regular path: C:\wamp\ and it still works.

5wins2.jpg


I use localhost, because I have a web sever running on my laptop.

Are you sure you are allowing the popups? Does IE show any security warnings?

Also the Windows all appear one over the other so it can look like just one. I just moved them for illustration purposes.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
[0]
>setTimeout(Win = window.open('', 'win'+i, 'width=50,height=50'),50);
[tt]setTimeout("Win = window.open('', 'win"+i+"', 'width=50,height=50')",50);[/tt]

[1] Or if Win being an array means what it means to be, you make it a global variable, defined outside of the function.
[tt]
[red]var Win=new Array();[/red]
function Launch() {
[red]//[/red]var Win = new Array();
for (var i=0; i < 5;i++){
setTimeout("Win["+i+"] = window.open('', 'win"+i+"', 'width=50,height=50')",50);
}
}
[/tt]
[2] If the original works, it is by some good fortune and cannot rely upon in general.
 
Hello:

Unfortunately I still can't get it to work. Here is the coding:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
   <title>Open Multiple Windows</title>
   <script language="Javascript" type="text/javascript">
   <!--

      var Win=new Array();
      function Launch() { 
         for (var i=0; i < 5;i++){
    setTimeout(&quot;Win[&quot;+i+&quot;] = window.open('', 'win&quot;+i+&quot;', 'width=50,height=50')&quot;,50);
   }
}



--> 

</script>

</head>
   <body>
      <form action="[URL unfurl="true"]http://www.jimkeogh.com"[/URL] method="post">
         <p>
<input name="WindowsGoneWild" value="Windows Gone Wild" type="button" onclick="Launch()"/>
         </p>
     </form>
   </body>
</html>

I enabled pop-ups but can only get 1 window. I am using vista with IE7
 
This way:

Code:
 setTimeout("Win["+i+"] = window.open('', 'win"+i+"',

Doesn't populate the array correctly, and I only get 1 window opened.

My other way, at least opened the windows, every time for me, even though it did generate errors I was not aware of, since I didn't check for them because it was technically working.

After a while of tinkering, I came up with this, that still works in IE for me when opened locally: "C:\dir\file.html", and generates no errors whatsoever.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
   <title>Open Multiple Windows</title>
   <script language="Javascript" type="text/javascript">
   <!--
       var Win = new Array();

    function Launch() {
        
         
         for ([red]var[/red] i=0; i < 5;i++)
         {
            Win[i] = window.open('', 'win'+ i, 'width=50,height=50');
         }
       

alert(Win[4].name);
}
-->

</script>

</head>
   <body>
      <form action="[URL unfurl="true"]http://www.jimkeogh.com"[/URL] method="post">
         <p>
<input name="WindowsGoneWild" value="Windows Gone Wild" type="button" onclick="Launch()"/>
         </p>
     </form>
   </body>
</html>

It will even alert the correct name afterward. Something my other codes failed to do in some instances.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Opening Multiple Windows - Solved:

Hello Everybody:

I finally solved the problem. I realized that there are 3 locations (not 2) that control pop-ups. They are:

1) Go to Tools, Internet Options, Privacy, then make sure that the Pop-up blocker is not checked, then click OK.

2) Go to the Google Toolbar and make sure that pop-ups are not blocked.

3) Go to the Verizon Toolbar and make sure that pop-ups are not blocked.

The entire code is:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
   <title>Open Multiple Windows</title>
   <script language="Javascript" type="text/javascript">
   <!--
      function Launch() { 
         var Win = new Array(); 
         for (i=0; i < 5;i++) 
         {
            Win[i] = window.open('','win'+i,'width=50,height=50') 
         } 
       } 
--> 

</script>

</head>
   <body>
      <form action="[URL unfurl="true"]http://www.jimkeogh.com"[/URL] method="post">
         <p>
<input name="WindowsGoneWild" value="Windows Gone Wild" type="button" onclick="Launch()"/>
         </p>
     </form>
   </body>
</html>
 
What I posted presume using setTimeout() and that's is the way to pass the string for eval(). The rest I don't look at much. That's so common.
 
I'm trying to open up 5 windows at a time because I am learning JavaScript from a book and that is one of the exercises.

As a side note, I'd love to know which book encourages visually raping us with masses of popups that we neither want nor care about...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top