Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); ui->webView->load(QUrl("test.htm")); connect(ui->webView, SIGNAL(loadFinished(bool)), SLOT(debug()));}void Widget::debug() { QWebElement document = ui->webView->page()->mainFrame()->documentElement(); QWebElement element = document.findFirst("script[type=\"text/javascript\"]"); element.appendInside("function Activate() {alert(\"WTF?\")}");}
C++ (Qt)ui->webView->page()->mainFrame()->evaluateJavaScript();
C++ (Qt)ui->webView->page()->mainFrame()->evaluateJavaScript("alert('!!!')");
Javascriptdocument.getElementById("xxx").onclick = myfunc();
Javascriptdocument.getElementsByName("mybutton")[0].onclick = myfunc()
C++ (Qt)webElement->setAttribute ("onclick", "myfunc(alert('!!!'))");