I’ve been using a bit of code (by John Evans) to execute javascript from within Dart:
void injectJavascript(String javascript, [bool removeAfter = false]){
var s = new Element.tag("script");
s.attributes["type"] = "text/javascript";
s.text = javascript;
document.body.nodes.add(s);
if (removeAfter != null && removeAfter)
s.remove();
}
injectJavascript("alert('using javascript')");
But I haven’t been able to send or return variables. Is this currently possible? If not, any idea when it will become possible?
You will need to use postMessage to do this. For example if you have converted your variable into JSON then you can do this from inside Dart
and then pick it up from the JavaScript side like this
If you need to work with more advanced things such as two way communication and callbacks then take a look at the code for DartGap in particular the DeviceMessageRouter class and the javascript integration layer.