Open the same window multiple times with JavaScript

I am new to JavaScript and trying to learn. How can I open the same window multiple times using JavaScript? Also, this did not work when I changed the function name.

Here is the function:

<script type='text/javascript'> function window(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=800,left = 650,top = 250');"); } </script> 
+4
source share
6 answers

Try something like this:

 var numWindows = 0; var windows = new Array(100); var parameters = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=800,left = 650,top = 250"; function openNewWindow(url) { numWindows += 1; var title = "Window #"+numWindows; windows[numWindows] = window.open(url, title, parameters); } 

To access the windows, do the following:

 windows[num] 

where num is the window identifier. The first id is 1, the second is 2, and so on.

+3
source

Use a random number to open the popup as many times as you want:

 function openPopUp (url) { var randomno = Math.floor((Math.random()*100)+1); window.open(url,'PopUpWindow'+randomno,'scrollbars=1,menubar=0,resizable=1,width=850,height=500'); } 
+3
source

The second parameter window.open () (here it is the timestamp) must be different, otherwise window.open () will load a new window inside the existing one (opened earlier with the same name → what the second parameter assigns to the window).

You can also use "_ blank" as the second parameter for open ()

+2
source

Try to exclude id parameter, for example:

 <script type='text/javascript'> function window(URL) { window.open(URL,'','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=800,left=650,top=250'); } </script> 
+1
source

First, I highly recommend that you stop using eval. This is very unsafe and not good to use.

Secondly, you can do this without eval like this:

 function openWindow(URL) { day = new Date(); id = day.getTime(); windowCol[id] = window.open(URL, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=800,left = 650,top = 250'); } 

And just to avoid confusion, although the "window" works as the name of a function, I would suggest changing it to make the code more readable, since it can get confused with the global window object.

+1
source

Try it.

 <script type='text/javascript'> function window(URL) { window.open(URL, "_blank", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=800,left = 650,top = 250'); } </script> 
0
source

Source: https://habr.com/ru/post/1338519/


All Articles