Clicking Anchors

14 views
Skip to first unread message

wrps...@aol.com

unread,
Jan 31, 2012, 5:06:33 PM1/31/12
to greasemonkey-users
I have this HTML in a page:

<a href="#" onClick="return sortTable( 'sortById', 'byId' )"><img
src="/sortById.gif" alt="Sort by ID" border="0" /></a>

I want to to automatically click the link when the page is loaded.

I have tried various approaches, but nothing works.

oAnchor.click();

unsafeWindow.sortTable('sortById', 'byId');

Anyone know how to do this?


Anthony Lieuallen

unread,
Jan 31, 2012, 5:29:13 PM1/31/12
to greasemon...@googlegroups.com
http://groups.google.com/group/greasemonkey-users/t/a64b797ab82bff7c



--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To post to this group, send email to greasemon...@googlegroups.com.
To unsubscribe from this group, send email to greasemonkey-us...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.


Robert

unread,
Jan 31, 2012, 5:46:29 PM1/31/12
to greasemon...@googlegroups.com

I want to to automatically click the link when the page is loaded.

I asked about the same a couple of days ago. Attached you will find my solution.

The only tricky thing might be getting the correct node to click (because there is no "id"-attribute).


Assuming that there might be something like
<div id="MyDIV">

<a href="#" onClick="return sortTable( 'sortById', 'byId' )"><img src="/sortById.gif" alt="Sort by ID" border="0" /></a>
</div>
you can do it like
$click( $( '<a', $( '#MyDIV' ) )[0] );
respectivly
var div = $( '#MyDIV' );
var a   = $( '<a', div );
$click( a );



Hope it helps,
Robert


Robert

unread,
Jan 31, 2012, 5:54:11 PM1/31/12
to greasemon...@googlegroups.com
Ooops... :)

var div = $( '#MyDIV' );
var a   = $( '<a', div );
$click( a[0] );

Reply all
Reply to author
Forward
0 new messages