Steven Yong
Steven Yong

Reputation: 5426

Automatic click a button when the page loads with GreaseMonkey

I am new to Grease Monkey and I need to click this Delete button

<TD nowrap width="20" height="18" valign="middle" align="center"><A href="JavaScript:SetCmd(document.msgViewer.CmdDelete.value);" title="Delete"><IMG border="0" src="https://webmail.myweb.com.au/exchweb/img/delete.gif" alt="Delete"></A></TD>

after the page is loaded using Grease Monkey

Full page here:

http://pastebin.com/DUytjGAh

Is this possible and how should I go about it?

This is so that I can delete my more than 10K spam email automatically. I already selected all the email items using Grease Monkey so now I need to press the Delete button.

Upvotes: 0

Views: 2847

Answers (3)

RozzA
RozzA

Reputation: 609

after checking the desired emails to delete,
SetCmd(document.msgViewer.CmdDelete.value);

Upvotes: 0

Brock Adams
Brock Adams

Reputation: 93443

This is one case where it's perfectly fine to use unsafeWindow.

So assuming that the emails are properly selected (which may be more than just checking a checkbox) and any AJAX delays/reloading are accounted for, then this code should do the trick:

unsafeWindow.SetCmd (unsafeWindow.document.msgViewer.CmdDelete.value);


Alternatively, you may find it easier to generate a click event.

Upvotes: 2

david.emilsson
david.emilsson

Reputation: 2331

Just run the JavaScript as defined in the href parameter of the anchor tag.

Upvotes: 1

Related Questions