Pass urls stored in array to window.open in for loop - Javascript -
this question has answer here:
i'm trying step through array , pass urls stored there window.open function. have.
$('a.linked').click(function(e) { e.preventdefault(); var i; var urls = ['http://example.com', 'http://example2.com', 'http://example3.com']; (i = 0; < urls.length; i++) { var ts = i*3500; settimeout(function(){window.open(urls[i]); }, ts); } });
this opening new windows @ correct timing i'm getting about:blank. thought might not escaping quotes.
the duplicate answer says i'm losing value of
i
however, when remove settimeout new windows correct urls. following code demonstrates not losing value of i.
$('a.linkedinprofiles').click(function(e) { e.preventdefault(); var i; var urls = ['http://example.com', 'http://example2.com', 'http://example3.com']; (i = 0; < urls.length; i++) { var ts = i*3500; {window.open(urls[i]); }; } });
i know has simple missing. in advance.
may not full solution, try adding "http://" beginning of urls. opened relative links.
Comments
Post a Comment