The js.dart library allows Dart code running in the browser to manipulate JavaScript running in the same page. It is intended to allow Dart code to easily interact with third-party JavaScript libraries.
See API documentation.
See samples that demonstrate interaction with JavaScript code. These include interoperation with the Google Maps JavaScript library, the Google Visualization JavaScript library, and Twitter's query API via JSONP.
The Dart Editor now includes pub support. To try out this library in the editor:
From the "File" menu, open a "New Application" (and make sure "Add Pub support" is checked).
Add the following to your pubspec.yaml:
dependencies:
js: any
Under the "Tools" menu, run "Pub Install".
Try the following test Dart file:
import 'package:js/js.dart' as js;
void main() {
js.context.alert('Hello from Dart via JS');
}
First, use the Pub Package Manager to install dependencies:
pub install
To run browser tests on Dartium, simply open test/browser_tests.html in Dartium.
To run browser tests using JavaScript in any modern browser, first use the following command to compile to JavaScript:
dart2js -otest/browser_tests.dart.js test/browser_tests.dart
and then open test/browser_tests.html in any browser.
Add this to your package's pubspec.yaml file:
dependencies: js: 0.0.22
If your package is an
application package you should use any
as the
version constraint.
If you're using the Dart Editor, choose:
Menu > Tools > Pub Install
Or if you want to install from the command line, run:
$ pub install
Now in your Dart code, you can use:
import 'package:js/ js.dart';
| Version | Uploaded | Archive |
|---|---|---|
| 0.0.22 | Apr 24, 2013 | Download js 0.0.22 archive |
| 0.0.21 | Apr 19, 2013 | Download js 0.0.21 archive |
| 0.0.20 | Apr 16, 2013 | Download js 0.0.20 archive |
| 0.0.19 | Apr 09, 2013 | Download js 0.0.19 archive |
| 0.0.18 | Mar 19, 2013 | Download js 0.0.18 archive |
| 0.0.17 | Mar 06, 2013 | Download js 0.0.17 archive |
| 0.0.16 | Feb 13, 2013 | Download js 0.0.16 archive |
| 0.0.15 | Jan 23, 2013 | Download js 0.0.15 archive |
| 0.0.14 | Jan 22, 2013 | Download js 0.0.14 archive |
| 0.0.13 | Dec 07, 2012 | Download js 0.0.13 archive |