Kirix Support Forums

How can I handle DOM event?

Please post all general questions, comments, bug reports, and any other wxWebConnect feedback here.

How can I handle DOM event?

Postby liyirong on Wed Dec 07, 2011 4:03 am

Today, I found this website and found this great control.
I tried to use this control in my project.
At the beginning, everything is OK.
But soon I found I cannot handle DOM event.
I want to handle a button event from the DOM.
I used a function named 'AddEventListener', but noting happened.
The following is my code.

Code: Select all
const int wxID_WEB = 9001;
const int WX_CLICK_EVENT = 999991;

class MyFrame : public wxFrame
{
    ...
    void OnDOMContentLoaded(wxWebEvent& evt);
    void OnDOMEvent(wxWebEvent &evt);
    ...
}

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    ...
    EVT_WEB_DOMCONTENTLOADED(wxID_WEB, MyFrame::OnDOMContentLoaded)
    EVT_WEB_DOMEVENT(wxID_WEB, MyFrame::OnDOMEvent)
    ...
END_EVENT_TABLE()

void MyFrame::OnDOMContentLoaded(wxWebEvent& evt)
{
   wxDOMDocument document = m_browser->GetDOMDocument();

   wxDOMElement ele = document.GetElementById(wxT("mybt"));
   if (ele.IsOk())
   {
      ele.SetAttribute(wxT("value"), wxT("Hello"));
      ele.AddEventListener(wxT("onclick"), this, WX_CLICK_EVENT, true);
   }
}

void MyFrame::OnDOMEvent(wxWebEvent &evt)
{
   OutputDebugString(wxT("DOM event!!\n"));
}


The function 'OnDOMEvent' hasnot been called when I click the button.
I hope you answer
Thank you
Last edited by liyirong on Wed Dec 07, 2011 12:21 pm, edited 1 time in total.
liyirong
Registered User
 
Posts: 2
Joined: Wed Dec 07, 2011 3:43 am

Re: How can I handle DOM event?

Postby liyirong on Wed Dec 07, 2011 12:20 pm

I think I found the problem.
The problem is the event table.
At first, I define the table as following

Code: Select all
EVT_WEB_DOMEVENT(wxID_WEB, MyFrame::OnDOMEvent)

No event coming.
Then, I define the table as following

Code: Select all
EVT_WEB_DOMEVENT(wxID_ANY, MyFrame::OnDOMEvent)

The DOM event can be handled.
liyirong
Registered User
 
Posts: 2
Joined: Wed Dec 07, 2011 3:43 am

Return to wxWebConnect Questions, Thoughts & Feedback