Following the example in the Getting Started page I parse the document nodes as follows:
void MyFrame::OnDOMContentLoaded(wxWebEvent& evt)
{
wxDOMDocument doc = m_browser->GetDOMDocument();
GetTitle(doc);
...
}
void MyFrame::GetTitle(wxDOMNode node)
{
if (!node.IsOk())
return;
wxDOMNodeList nodelist = node.GetChildNodes();
int i, count = nodelist.GetLength();
for (i = 0; i < count; ++i)
{
wxDOMNode node = nodelist.Item(i);
wxDOMHTMLElement titu = node;
if (titu.IsOk())
{
wxString titulo = titu.GetTagName();
if (titulo.CmpNoCase(_T("title")) == 0)
{
//here I intend to change the title
//first I try to get the current title, to be sure the code is working
//I tried titu.GetTitle() to no avail
//does somebody knows how to get/change the document title using the DOM?
return;
}
}
GetTitle(node);
}
}
Using XULRunner 1.9.1.19
Thanks in advance,
Daniel
Kirix Support Forums
Reading/Changing the document title
3 posts
• Page 1 of 1
- dancb
- Registered User
- Posts: 7
- Joined: Sat Aug 27, 2011 7:17 am
Re: Reading/Changing the document title
Finally I found how to change the document title:
- Code: Select all
if (currentNode.IsOk())
{
wxString titulo = currentNode.GetTagName();
if (titulo.CmpNoCase(_T("TITLE")) == 0)
{
if (currentNode.HasChildNodes())
{
wxDOMNodeList nl = currentNode.GetChildNodes();
wxDOMText titu = nl.Item(0);
titu.SetNodeValue(_T("any_name"));
}
return;
}
}
- dancb
- Registered User
- Posts: 7
- Joined: Sat Aug 27, 2011 7:17 am
Re: Reading/Changing the document title
Another way to change the document title (and indeed to do most DOM manipulation) is to use Javascript. The WebControl method Execute() will enable you to execute an arbitrary chunk of Javascript (though from memory it does not work in WebConnect 1.1, check my previous posts for more information on this).
In Python, I would probably do:
webcontrol.Execute('document.title = "My title";')
In Python, I would probably do:
webcontrol.Execute('document.title = "My title";')
- jonmmorgan
- Registered User
- Posts: 94
- Joined: Fri May 14, 2010 9:48 am
3 posts
· Page 1 of 1
Return to wxWebConnect Questions, Thoughts & Feedback