开发者

Help clicking a button in Greasemonkey

1st- I'm not a programmer, so assume I know nothing about JavaScript. In fact, I just figured out that Greasemonkey is JavaScript. 2nd - But I have been searching and reading for several days trying to do it myself. I'm not lazy, it's just that I'm in way over my head.

http://userscripts.org/scripts/review/57265 The program automatically clicks a radio button and adds a new button. When you click the new button it automatically fills text in the box. I'm trying to simply modify this Greasemonkey Script to automaticaly click the new button.

But I've learned this isn't so simple. Apparently I need an XPath for this? That's about all I've figured out so far. I really don't want to learn all of JavaScript just to do this one thing.

I've tried inserting this in at the end:

function click(elm) { var evt = document.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true, window, 0, 1, 1, 1, 1, false, false, false, false, 0, null); elm.dispatchEvent(evt);

It didn't work. Maybe I'm missing something?

I also tried this from another program:

  var rep = document.getElementById("report");
  if( (rep != null) ) ) {
  var repk = rep.childNodes;
  for( var repidx=0; repidx<repk.length; repidx++ ) {
      var rep2 = repkrepaidx];

}

But again I don't think I put 开发者_StackOverflowit in right?


assuming the "report" in your example is a form, you can just submit it.
form.submit

If the element used to submit the form is input type="submit" or input type="button", you can "click" it.
buttonElement.click();

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜