Reputation: 345
I have an array like
myArray = ["http://www.google.co.uk", "http://www.ebay.co.uk"]
and I want to open them all in a new tab. The code I am using just puts all the urls together and tried to open it in one.
Any help greatly appreciated
$.each(
myArray,
function( intIndex, objValue ){
window.open(myArray);
}
);
})
Upvotes: 0
Views: 2379
Reputation: 513
The correct code is:
var myArray = ["http://www.google.co.uk", "http://www.ebay.co.uk"];
$(document).ready(function() {
$.each(
myArray,
function( intIndex, objValue ){
window.open(objValue);
});
});
You used the array variable in window.open, thats why it was joining the urls.
Upvotes: 0
Reputation: 62488
you are passing whole myArray
to window.open()
, you have to pass each item value.
change:
window.open(myArray);
to:
window.open(objValue);
Like this:
var myArray = ["http://www.google.co.uk", "http://www.ebay.co.uk"];
$.each(myArray,function (intIndex, objValue) {
window.open(objValue);
});
http://jsfiddle.net/ehsansajjad465/4jj9x3z5/
Upvotes: 2