This is an old revision of the document!
Multiple consecutive redirects using a JavaScript Popup
In project.net, the project management application we are using, you can't directly link to e.g. a discussion group. You have to click on the respective business, then on Discussions and afterwards on the group itself.
In order to automate this, we created a link to a JavaScript popup that then redirect to one page after the other. The relevant code is the following:
function pop_redirect() {
attr = 'resizable=no,scrollbars=yes,width=150,height=100';
popWin=open('', 'new_window', attr);
popWin.document.write('<head><title>Test Popup</title>');
popWin.document.write('<scr'+'ipt language="JavaScript">');
popWin.document.write('function last_redirect(){\n');
popWin.document.write('if(opener && !opener.closed){\n');
popWin.document.write('opener.location.href="http://last_url.com";\n');
popWin.document.write('window.close();\n');
popWin.document.write('}\n');
popWin.document.write('}\n');
popWin.document.write('function redirect2(){\n');
popWin.document.write('if(opener && !opener.closed){\n');
popWin.document.write('opener.location.href="http://second_url.com";\n');
popWin.document.write('setTimeout("last_redirect()", 500);\n');
popWin.document.write('}\n');
popWin.document.write('}\n');
popWin.document.write('function redirect_board(){\n');
popWin.document.write('if(opener && !opener.closed){\n');
popWin.document.write('opener.location.href="http://first_redirect.com";\n');
popWin.document.write('setTimeout("redirect2()", 500);\n');
popWin.document.write('}\n');
popWin.document.write('}\n');
popWin.document.write('setTimeout("redirect_board()", 500);');
popWin.document.write('<\/scr'+'ipt>\n');
popWin.document.write('</head>\n');
popWin.document.write('<body onload="redirect_board()">');
popWin.document.write('Processing done...Please wait.<br>If it does not work, click <a href="javascript:redirect_board()">here</a>');
popWin.document.write('</body>');
popWin.document.write('</html>');
}
And the relevant link is just a javascript link using
<a href="#" onClick="board_redirect()">Redirect Me</a>
Update: The following accepts an array of URLs to cycle through:
function redirect(urllist)
{
attr = 'resizable=no,scrollbars=yes,width=150,height=100';
popWin=open('', 'new_window', attr);
popWin.document.write('<head><title>Redirecting...</title>');
//popWin.document.write('</head><body>');
popWin.document.write('<scr'+'ipt language="JavaScript">');
popWin.document.write('var urllist = new Array(' + urllist.length + ');\n');
for(i=0;i<urllist.length;i++)
{
popWin.document.write('urllist[' + i + '] = "' + urllist[i] + '";\n');
}
popWin.document.write('function redirect(i){\n');
popWin.document.write('if(i == urllist.length){\n');
popWin.document.write('window.close();\n');
popWin.document.write('}\n');
popWin.document.write('else {\n');
popWin.document.write('if(opener && !opener.closed){\n');
popWin.document.write('opener.location.href=urllist[i];\n');
popWin.document.write('i=i+1;\n');
popWin.document.write('setTimeout("redirect(" + i + ")", 500);');
popWin.document.write('}\n');
popWin.document.write('}\n');
popWin.document.write('}\n');
popWin.document.write('<\/scr'+'ipt>\n');
popWin.document.write('</head>\n');
popWin.document.write('<body>\n');
popWin.document.write('Processing done...Please wait.<br>If it does not work, click <a href="javascript:redirect(0)">here</a>\n');
popWin.document.write('</body>\n');
popWin.document.write('</html>\n');
popWin.onload = popWin.redirect(0);
}
And then call it using the following statement:
<a href="#" onClick='javascript:redirect(["http://www.google.at", "http://www.gmx.at", "http://www.facebook.com"])'>Redirect</a>