5

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

1
  • Did you try e.click()? (With parentheses.) Commented May 18, 2012 at 7:36

6 Answers 6

4

use jquery like

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

You can use trigger:

Sign up to request clarification or add additional context in comments.

6 Comments

My problem is, I wish to execute the code from a browser, Is this possible?
@Nookster - if you want to redirect to other page on click...than you can use "location.href = linkhref" which will cause page to redirect to other page....
How can I execute it in a browser using format such as this: javascript:function x() { $("a").each(function (i, a) {alert(a.href);a.click();});}x(); With this code I get a.click function not defined
@Nookster - you can do is $(this).trigger('click');//for clicking element
It's not working executing via the browser address bar, this is what I need it for - any ideas?
|
1

With JQuery you could use this :

$("a").each(function(){
    alert($(this).attr('href'));
    $(this).trigger('click');
};

3 Comments

This looks good, But I need to execute it via the browser with javascript:xx_code_here I cannot get this code to work like this, any ideas?
you can execute jquery code via browser, you have to use basic javascript without lib. Your code seems good to do it, just change e.click in this.click(), should work
How can I check for specific URLs and click only those ?
1

This Worked for Me

Each link is opened in New Tab

$("a").each(function ()
{
    window.open($(this).attr('href'),"_blank");
});

If At first time this time links are not opened , then you have to enable popups on the webpage .

Comments

0
$("a").each(function ()
{
    window.location.href = $(this).attr('href');
    // $(this).trigger('click');
});

Comments

0

You can do this with pure-javascript

function x() { // Please find a better name!
    for(var a in document.getElementsByTagName("a")) {
        alert(a.href);
        a.click(); // Careful, IE only, see comments
    }
}

With jQuery, you have shorter code:

function x() {
    $("a").each(function (i, a) {
        alert(a.href);
        a.click();
    });
}

3 Comments

Hello, Thanks for the reply It's called X because I want to excute it from the browser like so: javascript:function x() { $("a").each(function (i, a) {alert(a.href);a.click();});}x(); However, This returns with a.click [undefined] is not a function, it displays the alert however..
As far as I'm aware the click() method is IE only, so if your planning on using pure js you should probably write a click method yourself. This thread describes how: stackoverflow.com/questions/902713/…
I need to invoke the click as if it was clicked via the user, I think jquery handles it but I also need to execute this in the browser address bar with javascript:xxxx any ideas?
0
javascript: var validUrls = ["http://targetsite.com/votefraud1","http://targetsite.com/votefraud2","http://targetsite.com/votefraud3"];

function x() { 
 for(var a in document.getElementsByTagName("a")) {
   if(validUrls.indexOf(a.href) != -1){
      window.open(a.href,'');
    }
  }
}

x();

If this doesn't work we might need more info on what exactly the click event is supposed to do on whatever site you're trying to game the voting system on

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.