I used Qt before Golang, I can use javascript in Qt like this:
QWebView* view = new QWebView(parent);
view->load(QUrl(""));
QString cmd("example.value = \"test\""); //using javascript to fill value
view->page()->mainFrame()->evaluateJavaScript(cmd);
QString cmd2("document.forms[\"Form1\"].submit()");//using javascript to submit a Form
QVariant result = view->page()->mainFrame()->evaluateJavaScript(cmd2);
qDebug() << result.toString(); //get javascript return data
How can I use javascript in Golang to get a specific website elements or submit forms.
I used Qt before Golang, I can use javascript in Qt like this:
QWebView* view = new QWebView(parent);
view->load(QUrl("http://www.example."));
QString cmd("example.value = \"test\""); //using javascript to fill value
view->page()->mainFrame()->evaluateJavaScript(cmd);
QString cmd2("document.forms[\"Form1\"].submit()");//using javascript to submit a Form
QVariant result = view->page()->mainFrame()->evaluateJavaScript(cmd2);
qDebug() << result.toString(); //get javascript return data
How can I use javascript in Golang to get a specific website elements or submit forms.
Share Improve this question asked Feb 8, 2015 at 6:15 Green BirdGreen Bird 1992 silver badges7 bronze badges 1- 1 Are you running Go on the client side, or on the server? – Jonathan Hall Commented Nov 30, 2015 at 17:00
2 Answers
Reset to default 2How can I use javascript in Golang
You can use gopherjs, a piler from Go to JavaScript.
You can see an example in the tidwall/digitalrain
project, where the digitalrain.go
file access html elements
js.Global.Get("document").Get("head").Call("appendChild", sheet)
js.Global.Get("document").Set("title", "whoa")
(for a great effect)
If you like to run JS code in Go, try Otto (https://github./robertkrimen/otto), it's a JS VM written in Go and very powerful.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745266331a4619479.html
评论列表(0条)