开发者

Looking to automate a webpage with links using Javascript

I'开发者_如何学Pythonm new to programming and have a question related to HTML and Javascript. I have a HTML page with 100 links on it. I'm looking for a way wherein if I click on the first link then the rest of the links are clicked after it without me having to click them manually. Is there a way to do it?

Please help!!!


$("a:first").click(function() {
    $("a:not(:first)").click();
});

Sample working code: http://jsfiddle.net/EJY8s/


$('a').each(function() {
    $(this).click();
});

For full-syntax head to Jquery site documentation.


The following bit of Javascript will make it so you can click any one of those 100 links and open them each in a new window. 100 impressions, how nice.

$a = $("a");
$a.click(function(e){
    e.preventDefault();
    $a.each(function(){ window.open(this.href); });
});

Demo: jsfiddle.net/JB2YF

If you only want the first <a> to open all links, it's an easy tweak:

$("a:first").click(function(e){
    e.preventDefault();
    $("a").each(function(){ window.open(this.href); });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜