Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open the same window multiple times using JavaScript

Tags:

javascript

I'm new to JavaScript and trying to learn. How can I open the same window multiple times using JavaScript? Also, it didn't 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>
like image 899
Ching Ling Avatar asked Dec 22 '22 18:12

Ching Ling


1 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 this:

windows[num]

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

like image 199
Matt Eskridge Avatar answered Jan 13 '23 15:01

Matt Eskridge