I am creating a chrome extension for a clothing website that releases items at a certain time. The extension looks for a certain set of links that contain certain keywords. If it finds the links, it opens them. If not, it refreshes the page. I accomplish this by using Javascript and jQuery. The script is injected via a background script & tabs. Here is my code:
if ($("body").hasClass(" products us")) {
var firstitem_link = $("a[href*='mizuno']").attr('href');
var seconditem_link = $("a[href*='schott']").attr('href');
if (firstitem_link && seconditem_link) {
window.open(firstitem_link);
window.open(seconditem_link);
} else {
window.location.reload(true);
}
}
When I use this code and it finds the links, it opens them numerous times, as opposed to once for each. How can I fix this?