Umair Shah Yousafzai Umair Shah Yousafzai - 4 months ago 70
Javascript Question

iMacros is opening all the links in one tab one by one but not in every new tab?

I hope that everyone will be in perfect health.!
I wrote an iMacros script but it has a problem it never opens the links in the new tab but instead it opens the links one by one in the

TAB=2
i.e in the 2nd Tab while it perfectly shows that in every new link visit task it shows tab as
incremented by 1 as :

Tab=3
Tab=4
Tab=5
Tab=6


And goes on like that but still never opens the link in new tab but instead it just opens the new tabs but the link is visited in the 2nd tab..!

My Script :

var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="TAB T=1"+" \n";
test +="URL GOTO=http://clicksandearns.com/index.php?tp=paidclicks "+" \n";

iimPlay(test);


var a_list = window.content.document.getElementsByTagName("a");

var x = 2;
for (var i = 0, len = a_list.length; i < len; i++) {
var a = a_list[i];
if (a.href.indexOf("tp=visit") > -1) {
var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="TAB OPEN "+" \n";
test +="TAB T="+x+" \n";
test +="WAIT SECONDS=1 "+" \n";
test +="URL GOTO="+a.href+" \n";
test +="WAIT SECONDS=1 "+" \n";


iimPlay(test);
x++;
}

}


var x = 1;
for (var i = 2; i <= 36; i++) {
var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="' AD "+x+" \n";
test +="TAB T="+i+" \n";
test +="WAIT SECONDS=1 "+" \n";
test +="FRAME NAME=visit "+" \n";
test +="TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:ss ATTR=TYPE:Submit&&NAME:submit&&VALUE:Continue<SP>for<SP>Credit "+" \n";
test +="WAIT SECONDS=2 "+" \n";
test +="TAB CLOSE"+" \n";


iimPlay(test);
x++;

}


So if anyone can please have a look over my script and let me know that what is really going on wrong with it please.Will be too much grateful for that..!

Answer

Your code creates independent scripts for opening each tab, thereafter you can't navigate backwards. Solution is adding TAB T=1 at the end of each script.

for (var i = 0, len = a_list.length; i < len; i++) {
    var a = a_list[i];
    var test;
    test ="CODE:";
    test +="TAB OPEN "+" \n";
    test +="TAB T="+x+" \n";
    test +="WAIT SECONDS=1 "+" \n";
    test +="URL GOTO="+a.href+" \n";
    test +="WAIT SECONDS=1 "+" \n";
    test += "TAB T=1\n"    
    iimPlay(test);
    x++;    
}

Apart from that I noticed a_list[0] is not a URL. After ignoring a_list[0] and removing the filter "if (a.href.indexOf("tp=visit") > -1)" it worked. The script opens each link in a different tab and then navigates backwards while submitting and closing.

Comments