How to Alert (as in javacript) in DART!

3,803 views
Skip to first unread message

jalaj

unread,
Oct 13, 2011, 5:51:17 AM10/13/11
to General Dart Discussion
All examples I saw manipulate DOM... but couldn't find one (or
missed!) which throws a alert box. Anyone know how to write DART
implementation of Javascript code below?

<script>
alert('Hello World');
</script>

Nicolas Geoffray

unread,
Oct 13, 2011, 7:36:37 AM10/13/11
to jalaj, General Dart Discussion
Hi Jalaj,

Did you try 'window.alert'?

Cheers,
Nicolas 

jalaj

unread,
Oct 14, 2011, 2:34:38 AM10/14/11
to General Dart Discussion
Hi,
Thanks for reply.

on dartboard using window.alert also shows error ("cannot resolve
window")
url: http://try-dart-lang.appspot.com/s/1mEa

Would it behave differently on local system? still lost!!

Regards,
Jalaj

On Oct 13, 4:36 pm, Nicolas Geoffray <ngeoff...@google.com> wrote:
> Hi Jalaj,
>

Dan Grove

unread,
Oct 14, 2011, 3:10:33 AM10/14/11
to jalaj, General Dart Discussion
try-dartlang.com doesn't include DOM APIs, so this won't work.

On a local system, you could compile this and run it in the context of HTML:

#import("dart:dom");

void main() {
window.alert('stuff');

jalaj

unread,
Oct 14, 2011, 5:56:42 AM10/14/11
to General Dart Discussion
Hi,

I thought I can get to run dart code all on dartboard, without pain of
downloading from svn, but no pain no gain... I wish google could
include the VM into Chrome so that at least Chrome App developers
could readily switch to it...
Will download an svn client today, haven't used it ever.

Thanks a lot Nicolas and Dan.

suheimi

unread,
Oct 14, 2011, 7:44:10 AM10/14/11
to General Dart Discussion
Ok, this is the summary, step by step:

$ cd dart/client
$ vi alert.html

<html>
<body>
<script type='application/dart'>

#import("dart:dom");

main() {
window.alert('dart alert');
}

</script>
</body>
</html>

$ python tools/htmlconverter.py alert.html -o out/
$ google-chrome out/alert-js.html

Dan Diebolt

unread,
Oct 14, 2011, 7:50:54 AM10/14/11
to suheimi, General Dart Discussion
Does it strike anyone else is being odd that you have to explicitly import the dom when including dart via <script type='application/dart'> in a web page?

John Tamplin

unread,
Oct 14, 2011, 10:23:46 AM10/14/11
to Dan Diebolt, suheimi, General Dart Discussion
On Fri, Oct 14, 2011 at 7:50 AM, Dan Diebolt <dandi...@gmail.com> wrote:
Does it strike anyone else is being odd that you have to explicitly import the dom when including dart via <script type='application/dart'> in a web page?

For one, there are two different libraries for manipulating the DOM -- which one should it import for you?

See http://www.dartlang.org/articles/improving-the-dom/ for why.

--
John A. Tamplin
Software Engineer (GWT), Google
Reply all
Reply to author
Forward
0 new messages