I have a list of URLs in an Excel file. Each URL, when opened, changes, and I need to capture the new URL.
So I wrote some JS to open the file, get each cell, open a new tab with the URL, wait for it to change and grab the new URL, putting it into the cell again.
The problem is, the setTimeout instruction does not wait, so it grabs the same URL. Here's what I have:
for (var i = 0; i < excelRows.length; i++) {
var row = table.insertRow(-1);
/*This is just for me to test it with one URL*/
if (i < 2) {
var tempTab = window.open(excelRows[i].URL); /*excelRows is defined prior to this block of code*/
setTimeout(function(){excelRows[i].URL = tempTab.location.href;}, 3000);
}
var cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].URL;
}
I know, I'm supposed to close temptTab too, but I want to understand first why this executes immediately, if I'm using it asynchronous.