netpumber Posted December 14, 2009 Share Posted December 14, 2009 Halo out there! So listen to my story.. I want to make a web page that will do these simple things . It only for personal use so i have to tell you that i use Firefox if that info is useful. Ok.. lets continue. It wil have an array like below var myArray = [ 'http://www.google.com', http://www.bing.com', 'http://www.yahoo.gom']; now i want these sites that are in array page open them automatically in a new tabs after one minute each of them. E.g when i open this page with firefox , after a minute a new tab will be created and http://www.google.com loaded . After one minute do the same with bing.com and so on... This project as i can imagine needs a timer but for now i need your help on how to make it open in new tabs the array's items.. Thanks for any answer! Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 14, 2009 Share Posted December 14, 2009 set firefox to open new windows as tabs set a global counter var var counter = 0; then use javascript to setTimeout('openPage()',60000); then the function function openPage() { window.open(myArray[counter]); counter ++; } now just wrap this all in a for loop. for (var i=0;i<=myArray.length;i++) { // do the timeout here } You could also not have the global counter, and pass in the index of i as you loop. (probably more efficient) Quote Link to comment Share on other sites More sharing options...
netpumber Posted December 15, 2009 Author Share Posted December 15, 2009 Thanks for your answer my friend optikalefx but i am little new in javascript coding.. So here is what i have : <script type='text/javascript'> var counter = 0; var myArray = [ 'http://www.google.com', http://www.bing.com', 'http://www.yahoo.gom']; //function creation function openPage() { window.open(myArray[counter]); counter ++; } </script> I didn understand what exactly to put in the for loop and that you say "then use javascript to setTimeout('openPage()',60000);" Can you be more specific to understand better ? Thanks a lot my friend and sorry for my english ! Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 16, 2009 Share Posted December 16, 2009 Basically you want to find the length of the array, and loop through the array, and then for each index in the array, you want to set a timeout for 1 minute which is 60,000 miliseconds. so for(var i=0;i<=myArray.length;i++) { setTimeout("openPage('+myArray+')",60000); } so now your are passing the current value of the loop as a string to the function. This will launch after 60 seconds, again untested. function openPage(page) { window.open(page); } Quote Link to comment Share on other sites More sharing options...
netpumber Posted December 16, 2009 Author Share Posted December 16, 2009 Is this : <script type='text/javascript'> var myArray = [ 'http://www.google.com', http://www.bing.com', 'http://www.yahoo.gom']; for(var i=0;i<=3;i++) { setTimeout("openPage('+myArray+')",60000); } function openPage(page) { window.open(page); } </script> And in for loop the myArray.length is just a number as i put it here or something like this myArray.3 ? I run the above script but didnt worked..:s Quote Link to comment Share on other sites More sharing options...
netpumber Posted December 16, 2009 Author Share Posted December 16, 2009 So.. i said to try first without setTimeout and run this but didnt worked too var myArray = [ 'http://www.google.com', http://www.bing.com', 'http://www.yahoo.com']; for(var i=0;i<=3;i++) { window.open('+myArray[i]+'); } Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 17, 2009 Share Posted December 17, 2009 tested and working. You need to have popup blocking OFF for window.open to work. <html> <head> <script type='text/javascript'> function openPages() { var myArray = [ 'http://www.google.com', 'http://www.bing.com', 'http://www.yahoo.com']; for(var i=0;i<=myArray.length-1;i++) { setTimeout("openPage('"+myArray[i]+"')",2000*i); } } function openPage(page) { window.open(page); } </script> </head> <body onload="openPages()"> </body> </html> Quote Link to comment Share on other sites More sharing options...
netpumber Posted December 17, 2009 Author Share Posted December 17, 2009 Oh!! Thanks a lot my friend.. Quote Link to comment Share on other sites More sharing options...
netpumber Posted January 15, 2010 Author Share Posted January 15, 2010 Ok.. I have one more question. Is it possible to make this script when it is opens the new tab close the old one ? e.g Lets say that we have these sites: http://www.google.com http://www.bing.com http://www.yahoo.com First it opens the google and after some time it opens the bing. I want when it opens the bing tab close the tab with google..and so on.. when it opens the yahoo tab close the bings tab. Is this possible or not ? Thanks in advanced.. Quote Link to comment Share on other sites More sharing options...
godsent Posted January 16, 2010 Share Posted January 16, 2010 try window.opener='x'; window.close(); Quote Link to comment Share on other sites More sharing options...
netpumber Posted January 16, 2010 Author Share Posted January 16, 2010 I don't think that this works.. I ll put it in the fuction under window.open(page); but nothing happened.. Quote Link to comment Share on other sites More sharing options...
netpumber Posted January 18, 2010 Author Share Posted January 18, 2010 Any other idea ? Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 1, 2010 Share Posted February 1, 2010 myWin = window.open(''); myWin.close(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.