[haXe] [js] being sure all is loaded before proecessing
Benjamin Dasnois
benjamin.dasnois at gmail.com
Mon Apr 3 20:15:17 CEST 2006
I can't understand why this may create problems if you want to
manipulate the DOM?! Simply put the js file just before the </body>
tag, no?
On 4/3/06, Franco Ponticelli <franco.ponticelli at gmail.com> wrote:
> Actually when you include you js (haxe generated), the main method is called
> on the end of the js parsing.
> This may create problems if your script pretends to manipulate the DOM of
> the page.
> To get around this I do the following:
> <code>
> class MainClass
> {
> static public function main() : Void
> {
> if(js.Lib.document.body == null)
> js.Lib.window.onload = onload;
> else
> onload(null);
> }
>
> static public function onload(evt : Event) : Void
> {
> js.Lib.alert("hello");
> }
> }
> </code>
>
> All my code goes in onload.
> Pay attention that I have had to add the event onload in the Window class
> (which is legal).
>
> This way you can include the js in the head instead of directly in the body
> ...
>
> Hope someone will find this useful :-)
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
>
--
DASNOIS Benjamin
More information about the Haxe
mailing list