0

I'm new to JavaScript: very different from Java lol :P I was wondering if I had a button, how could I continuously press that button on a 4-5 min interval? Here is the page source:

<head><title>A>
<link rel="stylesheet" href="i/w/i_style0n.css">
</head>
<body bgcolor=black topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>
<img src=i/w/sp_.gif height=2><br><table align=center cellspacing=0 cellpadding=2 width=800 style="border:solid 1px yellow;color:white;" bgcolor=#383838><tr><td align=center> &nbsp; <a href=/p/en/forum/read/100/29291/ target=blank>Raffle 12/11/12-25/11/12 </a> {<a href=hef.cfm?&3831&f=hef_detail&hi=29291&ch=100 target=_Blank>UC0</a>} ( <a href=/p/en/forum/read/100/28080/ target=_blank>Details</a> {<a href=hef.cfm?&3831&f=hef_detail&hi=28080&ch=100 target=_Blank>UC0</a>} . <a href=/p/en/forum/read/100/28201/ target=_blank>Winners</a> {<a href=hef.cfm?&3831&f=hef_detail&hi=28201&ch=100 target=_Blank>UC0</a>} ) - <a href=/p/en/forum/read/200/118678/ target=_Blank>Minor updates</a> {<a href=hef.cfm?&8950&f=he_detail&hi=118678&ch=200 target=_Blank>UC0</a>} - <a href=/p/en/forum/read/100/29293/ target=_Blank>Xmas Event </a> {<a href=hef.cfm?&3831&f=hef_detail&hi=29293&ch=100 target=_Blank>UC0</a>} &nbsp; </td></tr></table><img src=i/w/sp_.gif height=5><br><script>idir='i/w/';fdir='i/w/'; loadtop='sc;0;i.cfm;1;12;-999999999999;1149205838665;19979962050;0;Eli';</script><script src="i/w/j_fr_low.js"></script> <script>lowresbar('0;class=res;; class=res><a href=i.cfm?r' + Math.round(Math.random() * 1000000) + '&f=sc_event>;0;');</script><font class=ft>Research > Housing</font><br>&nbsp;<Br><table width=250 class=trane><tr class=tranbox2><td align=center><table border=0><tr><td class=cw>2,304 turns left in research !</td></tr></table></td></tr></table>&nbsp;<br><table cellspacing=0 cellpadding=2 border=0 align=center class=tranbox><tr class=tranbox2><td class=fs> &nbsp; 31 turn(s) used &nbsp; &nbsp; &nbsp;
Credit -188,302,058,116 &nbsp; Food +17,678,556 &nbsp; &nbsp; <font class=cr>Debt - 18,137,549,878</font>
<br><font class=fsr> &nbsp; Bankruptcy warning: Most production has stopped due to debt<br> &nbsp; Reduce your debt as soon as possible !</font></td></tr></table><img src=i/w/sp_.gif height=5><br>&nbsp;<br>
<script src="i/w/j_sc_research2.js"></script>
<script>
function x5n6z3(obj) { if(obj.value == "Start") obj.form.submit(); obj.value = "Wait!"; } function confirmflag() { if (confirm("")) document.location=frf+'?'+ranurl+'f=sc_research2&rtype='+rtype+'&del=1'; else return false; } 

res2('0;1;&kq7e&;Housing;157;2304;0;Start;Wait!;x5n6z3;y61lip;');
</script>
    <br>&nbsp;</td></tr></table></td><td class=fs> <script>ochat('');</script><font color=#747474>08:27 AM &nbsp; 24 Nov 2012<br>46 Player(s) Online<br>  0.05x Load (sec)</td></td></tr></table> <br><br></body></html>

I would like to click the button "Start" every 4-5 mins. Anyone able to help me with this?

Matt
  • 9
  • 1
  • Take a look at my answer to a similar question [**here**](http://stackoverflow.com/a/13409470/1615483) and combine it with [`window.setInterval`](https://developer.mozilla.org/en-US/docs/DOM/window.setInterval). – Paul S. Nov 24 '12 at 01:16
  • Uh, there is no "start" button in that code!   It looks like it might be added by javascript, but without knowing the actual website, we can't be sure. With the button visible on the page, use Firefox to save the page to disk (*Ctrl S*), then copy the `.htm` file to http://pastebin.com/ and link to that here. It would be best to link to the target page, too. – Brock Adams Nov 24 '12 at 01:29
  • Duplicate of http://stackoverflow.com/q/6466856/, http://stackoverflow.com/q/12252701 , http://stackoverflow.com/q/6337197 , and many others. ... ... Too localized in it's current form. – Brock Adams Nov 24 '12 at 01:40

1 Answers1

2

To simulate a click in JavaScript you can do code like I said in this answer..

function simulateClick(node) {
    var ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    return node.dispatchEvent(ev);
}

and combine this with window.setInterval

var nodeToClick = null, // some node
    clicker = function clicker() {
        simulateClick(nodeToClick);
    };
window.setInterval(clicker, 4*60*1000); // 1000ms in sec * 60secs in min * 4 mins
Community
  • 1
  • 1
Paul S.
  • 64,864
  • 9
  • 122
  • 138
  • This "how to click" but not how to click the OP's button. – Brock Adams Nov 24 '12 at 01:43
  • @BrockAdams I assumed OP knew how to get the node and set `nodeToClick`, I couldn't do it because OP's code doesn't have any ` – Paul S. Nov 24 '12 at 01:47
  • Not a valid assumption, I'd wager. We'll see, if the OP responds. ... The actual clicking is not the hard part. It's been answered in scores of questions -- the approach in your answer has been shown over and over (except that this answer will crash in most AJAX scenarios). – Brock Adams Nov 24 '12 at 01:48
  • Crashing in AJAX due to element changing? That's why `nodeToClick`'s `var` is outside the function `clicker` so you can change it and `clicker`s target will change too. If you're really worried about this you could get each time/check existence first. – Paul S. Nov 24 '12 at 02:03
  • Crashing because `nodeToClick` won't be present in the first run (or several runs). – Brock Adams Nov 24 '12 at 02:09