Hi, all:
I want to click a input button automaticlly inside mozilla. i wrote followed
source:
PRBool PSClickEvent::FireEvent(nsIContent *aNode)
{
nsCOMPtr<nsIDocument> doc = aNode->GetCurrentDoc();
if (doc)
{
nsCOMPtr<nsIDOMDocumentEvent> tmpDocEvent =do_QueryInterface(doc);
nsCOMPtr<nsIDOMEvent> tmpClickEvent;
nsAutoString tmpEvent(NS_LITERAL_STRING("MouseEvents"));
tmpDocEvent->CreateEvent(tmpEvent, getter_AddRefs(tmpClickEvent));
nsCOMPtr<nsIDOMMouseEvent> tmpMouseEvent =do_QueryInterface(tmpClickEvent);
nsAutoString tmpEventType(NS_LITERAL_STRING("click"));
//type, bubble, cancel, view
tmpMouseEvent->InitMouseEvent(tmpEventType, PR_TRUE, PR_TRUE, nsnull,
//screen, client rect
0, 0, 0, 0, 0,
//
PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE,
//
0, nsnull);
nsCOMPtr<nsIDOMEventTarget> tmpEventTarget =do_QueryInterface(aNode);
PRBool tmpEventRes;
tmpEventTarget->DispatchEvent(tmpClickEvent, &tmpEventRes);
return PR_TRUE;
}
return PR_FALSE;
}
html code:
<html>
<title> form-tt</title>
<body>
<form id="form_11" action="/cgi-bin/form-res.cgi" method="POST">
<input id="mm_text" name="ddd" type="text" value="test_1">
<input id="mm_button" name="ccc" type="button" value="Commit" onclick="counter
= 10+1; mm_text.value = mm_text.value +counter;">
<input id="mm_submit" name="sss" type="button" value="Submit"
onclick="form_11.submit();">
</form>
</body>
</html>
I post a event to main thread to call PSClickEvent::FireEvent(nsIContent
*aNode). if click commit button or Submit ,the result is OK.
if click Submit after clicked Commit, at this point URL changed, mainthread
excutes garbage collector to release js cache. i don't know why to release
tmpClickEvent object in GC.
I want to know how to trigger a click event on button ?
Xu Jianbin
2008-06-11
_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout