Jump to content

Openning web pages project


netpumber

Recommended Posts

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!

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 ! :)

 

Link to comment
Share on other sites

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);

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

  • 5 weeks later...

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..

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.