Prev | Current Page 741 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Now that you have a standard way to add and remove events, it is possible to write code that is executed
after the page loading completion to satisfy the JavaScript purists. This is very easy to accomplish now,
just add an event listener to the load event of the window object and put the initialization code in there.
(continued)
399
Chapter 14: More Interactive Content with JavaScript
import DomListener;
import js.Dom;
class Main
{
public static function main()
{
DomListener.add(js.Lib.window, ???load???, function(e)
{
var btn : Button = cast js.Lib.document.getElementById(???sbutton???);
DomListener.add(btn, ???click???, function(e)
{
js.Lib.alert(???Button Clicked!???);
});
});
}
}
The script can now be positioned correctly in the head element of the page.
< html >
< head >
< title > Example < /title >
< script type=???text/javascript??? src=???main.js??? > < /script >
< /head >
< body >
< button id=???sbutton??? > Display Message < /button >
< /body >
< /html >
To be fair, the page load event is not the best place to start the DOM manipulation.


Pages:
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753