Is there a way to pass a variable to the `chrome.tabs.create` function?
I am currently working on setting up event listeners for my anchors, but I am faced with a challenge as I am creating them within a for loop:
for (var i = 0; i < links.length; i++){
if(links[i][0] === text){
var a = document.createElement('a');
a.setAttribute('href', links[i][2]);
a.setAttribute('class','links_anchor');
a.innerHTML = links[i][1];
test = links[i][2];
a.addEventListener('click', function(){
chrome.tabs.create({
url: test,
active: false
});
});
document.getElementById('links_content').appendChild(a);
}
}
Is there any way to pass a unique variable to the `url` parameter? Currently, all the links trigger the same action. For example, every time I click on any link it opens the URL of the last item in the array.