1

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?

user3376905
  • 177
  • 1
  • 3
  • 11
  • visit this one for best reference http://stackoverflow.com/questions/7564392/open-multiple-tabs-on-a-single-window-by-a-single-click-using-javascript – chandu Apr 21 '14 at 15:49
  • You should put a bunch of console.log statements in that code to see which part is actually running more than once. We don't know where this outer if block is running, so our powers of deduction are limited. – sowbug Apr 21 '14 at 19:06
  • It isn't whole code. If this script opens new windows more than two times it means that this block is executed more than once. Find out why it is happening and you resolve the problem. – Pawel Uchida-Psztyc Apr 21 '14 at 21:48

0 Answers0