
Originally Posted by
Spitfire
As an alternative you can try QWebPage::currentFrame() or QWebPage::frameAt().
If you don't know how to call js inside iFrame from parent document consider this:
QWebView::page()->mainFrame()->evaluateJavaScript( "function call_iFrame() { document.getElementById('iframe_id').contentWindow.method_inside_iframe(); }" )
QWebView::page()->mainFrame()->evaluateJavaScript( "function call_iFrame() { document.getElementById('iframe_id').contentWindow.method_inside_iframe(); }" )
To copy to clipboard, switch view to plain text mode
That should get you going.
I am sorry I am resurrecting this topic, but following it I think this topic is incomplete and my question might start from this point.
Into an application that use a WebView I am loading some web content. Trying to execute a JavaScript code that call a alert() window directly into evaluateJavaScript() is fine, but calling it into a function it fails.
QString strTest1
("alert(\"this is sly!\"); null ");
QVariant f1result
= webView
->page
()->mainFrame
()->evaluateJavaScript
( strTest1
);
// fine QString strTest2
("function alert_something() { alert(\"this is sly!\"); } ");
QVariant f2result
= webView
->page
()->mainFrame
()->evaluateJavaScript
( strTest2
);
// bad
qDebug() << f2result.toString(); // returns nothing
QString strTest1 ("alert(\"this is sly!\"); null ");
QVariant f1result = webView->page()->mainFrame()->evaluateJavaScript( strTest1 ); // fine
QString strTest2 ("function alert_something() { alert(\"this is sly!\"); } ");
QVariant f2result = webView->page()->mainFrame()->evaluateJavaScript( strTest2 ); // bad
qDebug() << f2result.toString(); // returns nothing
To copy to clipboard, switch view to plain text mode
I can't figure why calling that trivial function call fails... Ideas?
Bookmarks