Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through links on site and click links javascript/jquery

I am trying to loop through all the links on a site and autoclick some links in order to vote for here is what I have so far:

    function x(){
        for(var e in document.getElementsByTagName("a")){ 
            alert(e.getAttribute("href"))
            e.click;
        }
    }

This currently does not work I think it maybe to do with something simple like the braces/; key, I'm an absolute beginner to javascript so please bear with me. I assume you get the drift of what I want to do, I have completed this task in another language but still did not get the vote to register, I believe this maybe something to do with the site using jquery? My question is, How can I get this simple script working for a start, and 2) Is there a different click method for Jquery I can use instead of what I have up there 3) How Can I check for 6 specific URLs and click only these. I also need to execute this from the browser using javascript:xxx_code_here

Any ideas?

Thank you

like image 595
Nookster Avatar asked May 18 '12 07:05

Nookster


1 Answers

use jquery like

$("a").each(function ()
{
   $(this).trigger('click');//for clicking element
   var href = $(this).attr("href");
});

You can use trigger:

like image 133
Pranay Rana Avatar answered Sep 23 '22 22:09

Pranay Rana