sand.fj.wen
23rd March 2009, 07:13
Hi everybody,
tody I use QWebView to load a html page, and want to add a custom HTML attribute "qlevel", someone told me QtWebKit doesn't offer DOM for HTML, so i want to use javascript to add this attribute, after adding the attribute, I want to export the HTML source, here is my code below:
//---------add custom attribute "qlevel"
QString strScript = "test.setAttribute = ('qlevel', '123');";
QWebFrame* pFrame = m_pView->page()->mainFrame();
pFrame->evaluateJavaScript(strScript);
//----------export the new html source
strScript="alert(test.innerText.toString());";
QMessageBox::information(this, tr("Test"), pFrame->evaluateJavaScript(strScript).toString());
QString strText = m_pView->page()->mainFrame()->toHtml();
QFile file("c:\\test.html");
file.open(QFile::WriteOnly);
QTextStream ts(&file);
ts << strText;
file.close();
the "test" in javascript is an id of TD tag, now in the new HTML source code, I couldn't see the ‘qlevel’ atrribute, why? Thanks!
tody I use QWebView to load a html page, and want to add a custom HTML attribute "qlevel", someone told me QtWebKit doesn't offer DOM for HTML, so i want to use javascript to add this attribute, after adding the attribute, I want to export the HTML source, here is my code below:
//---------add custom attribute "qlevel"
QString strScript = "test.setAttribute = ('qlevel', '123');";
QWebFrame* pFrame = m_pView->page()->mainFrame();
pFrame->evaluateJavaScript(strScript);
//----------export the new html source
strScript="alert(test.innerText.toString());";
QMessageBox::information(this, tr("Test"), pFrame->evaluateJavaScript(strScript).toString());
QString strText = m_pView->page()->mainFrame()->toHtml();
QFile file("c:\\test.html");
file.open(QFile::WriteOnly);
QTextStream ts(&file);
ts << strText;
file.close();
the "test" in javascript is an id of TD tag, now in the new HTML source code, I couldn't see the ‘qlevel’ atrribute, why? Thanks!