PDA

View Full Version : QWebView and evaluateJavaScript



hereiam
12th August 2013, 20:50
Hi there,

I want to write a programme with several QWebView's. So I created few QWebView's and load for every View another HTML Site. Then I want to delete from every site HTML links. I do this after loadFinished(bool) is emitted from QWebView with evaluateJavaScript() function.



web_view->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");


I reconginze that the function evaluateJavaScript() only works at its own object but if I load these HTML sites only links from the last loaded HTML are removed.


I that a normal behviour or how can I fix it that links are removed on every HTML site in a QWebView?

wysota
13th August 2013, 09:02
What do you mean by "every HTML site in a QWebView"?

hereiam
13th August 2013, 13:11
QFile file1, file2, file3;

file1.setFileName("site1.html");
file1.open(QIODevice::ReadOnly);

file2.setFileName("site2.html");
file2.open(QIODevice::ReadOnly);

file3.setFileName("site3.html");
file3.open(QIODevice::ReadOnly);

QWebView webview1 = new QWebView();
webview1->setContent(file1.readAll();

QWebView webview2 = new QWebView();
webview2->setContent(file2.readAll();

QWebView webview3 = new QWebView();
webview3->setContent(file3.readAll();


//...
//if page is loaded and loadFinished(bool) signal is emitted
//...
mweb_view1->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");
//...
mweb_view2->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");
//...
mweb_view3->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");

wysota
13th August 2013, 13:18
That doesn't really answer my question...