Hi,

i'm trying to simulate a click on an anchor (<A>) element. By calling
a InitMouseEvent the program exits because of segmentation fault.

My code fragment:
nsCOMPtr<nsIDOMHTMLAnchorElement> l_anchor(do_QueryInterface(domnode,
&rv));
        if (!NS_FAILED(rv) && l_anchor)
        {
        nsCOMPtr<nsIDOMDocument> OwnerDoc;
        l_anchor->GetOwnerDocument(getter_AddRefs(OwnerDoc));

        nsCOMPtr<nsIDOMDocumentView> doc =
do_QueryInterface(OwnerDoc);

        nsCOMPtr<nsIDOMAbstractView> view;
        doc->GetDefaultView(getter_AddRefs(view));

        nsCOMPtr<nsIDOMDocumentEvent>
docEvent(do_QueryInterface(OwnerDoc));

        nsCOMPtr<nsIDOMEvent>linkClickEvent;
        docEvent-
>CreateEvent(NS_LITERAL_STRING("MouseEvents"),getter_AddRefs(linkClickEvent));

        nsresult result;
        nsCOMPtr<nsIDOMMouseEvent> mouseEvt=
do_QueryInterface(linkClickEvent,&result);
        mouseEvt-
>InitMouseEvent(NS_LITERAL_STRING("click"),PR_TRUE,PR_TRUE,view,
0,0,0,0,0,PR_FALSE,PR_FALSE,PR_FALSE,PR_FALSE,1,nsnull);

        nsCOMPtr<nsIDOMEventTarget> evtTarget=
do_QueryInterface(l_anchor,&result);

        PRBool clickStatus;
        evtTarget->DispatchEvent(mouseEvt,&clickStatus);
}

Am i doing it correctly? Is there any other method to simulate such a
click? (but not reading a href address and redirecting there browser -
it is not enough for me).
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to