473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Scan page for links, open in new windows

58
Hey Everyone -

I'm working on a greasemonkey script and I'm having some trouble...

What I would like to do is to scan a page for links, store them, and then open them - one at a time - in a new window...eventually, I would like to have this timed (every 10 seconds or so) so that I could scan through a massive number of links automatically...

What I have so far is this:

Expand|Select|Wrap|Line Numbers
  1. var allLinks, thisLink;
  2. allLinks = document.evaluate(
  3.     '//a[@href]',
  4.     document,
  5.     null,
  6.     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  7.     null);
  8.  
  9.  
  10. var counter, whilecounter;
  11. counter  = 0;
  12. whilecounter = 0;
  13.  
  14.  
  15. while(counter<allLinks.snapshotLength && counter < 5){
  16.  
  17.     if(whilecounter == 10000){
  18.         thisLink = allLinks.snapshotItem(counter);
  19.         window.open(thisLink);
  20.         counter++;
  21.         whilecounter = 0;
  22.         continue;
  23.     }
  24.  
  25.     else{
  26.         whilecounter++;
  27.         }
  28.  
  29. } // end while
  30.  
This will get the windows to open, but they shut down after loading...
This is also an extremely ineffective timing system...does js have a timer
/clock that I can utilize?

Firebug keeps giving me an error .... _uVoid undefined


Any ideas?

Tom
Dec 23 '07 #1
2 1269
improvcornartist
303 Expert 100+
JavaScript has a setTimeout and setInterval which may work for you. The following script gets links on a page and opens one every 3 seconds. You may be able to modify it for your use.

Expand|Select|Wrap|Line Numbers
  1. var action, counter, allLinks;
  2. var allLinks = document.getElementsByTagName('a');
  3. var counter = 0;
  4. function openPage(){
  5.   if(allLinks[counter])
  6.     window.open(allLinks[counter]);
  7.   else
  8.     clearInterval(action);
  9.   counter ++;
  10. }
  11. function startOpeningLinks(){
  12.   action = setInterval('openPage()',3000);
  13. }
Then just call startOpeningLinks() to start.
Dec 23 '07 #2
tburger
58
thanks...looks awesome...

Tom
Dec 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sally B. | last post by:
Hello, I searched, but couldn't find answers--probably because I'm not sure what this is called... Anyway, I have about 50 web pages and I want to have some JavaScript that will read in a list of...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
13
by: Geoff Fox | last post by:
I am in the final moments of designing a new website. One of the pages (http://www.auditionfactory.com/samples.php) has four links to show sample work. I would like these links to open new...
1
by: codejunkie | last post by:
Hello everyone. Matt here. I've been struggling to find a solution to this problem. I need to scan a page for ALL and ANY links but preg_match_all as in this script can never do it: <?php $URL =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.