I have written a more generic function the perfectly fits my needs. So
if someone is interessted, feel free to use it.
// simulate mouse click on element
function $click( elm, root ) {
// create mouseclick element
var evt = document.createEvent( 'MouseEvents' );
evt.initEvent( 'click', true, true );
// id, class, tag, name or node itself?
var node;
if( typeof elm == 'string' ) {
if( elm[0] == '#' ) node = $( elm, root )
else node = $( elm, root )[0];
} else node = elm;
// click node
node.dispatchEvent( evt );
}
// Get Elements
function $( q, root, single ) {
if( root && typeof root == 'string' ) {
root = $( root, null, true );
if( !root ) { return null; }
}
root = root || document;
if( q[0] == '#' ) { return root.getElementById(q.substr(1)); }
else if( q[0] == '/' || ( q[0] == '.' && q[1] == '/' ) ) {
if( single ) { return document.evaluate(q, root, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }
return document.evaluate(q, root, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
} else if( q[0] == '.' ) { return
root.getElementsByClassName(q.substr(1)); }
else if( q[0] == ':' ) { return root.getElementsByName(
q.substr(1)); }
else if( q[0] == '<' ) { return root.getElementsByTagName(
q.substr(1)); }
return root.getElementsByTagName(q);
}
Regards,
Robert
-------- Original-Nachricht --------
Betreff: Re: [greasemonkey-users] Acting like a user?
Von: Robert <[email protected]>
An: [email protected]
Datum: Thu Jan 19 2012 21:42:36 GMT+0100
Ah! Great! Tnx!
This seems to be what I want:
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
el.dispatchEvent(evt);
Cheers,
Robert
-------- Original-Nachricht --------
Betreff: Re: [greasemonkey-users] Acting like a user?
Von: Anthony Lieuallen <[email protected]>
An: [email protected]
Datum: Thu Jan 19 2012 21:29:37 GMT+0100
http://wiki.greasespot.net/Generate_Click_Events
--
You received this message because you are subscribed to the Google
Groups "greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.
--
_ oRobert H. <mailto:[email protected]> http://kurzlink.de/Enkidu70
|<)_/#
TT<T [email protected] <mailto:[email protected]>
"Du wirst da hinein geboren was Du nicht bist, um zu erfahren wer Du
wirklich bist!"
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.