Hi,
while I dont have much of a clue of what I'm doing in Javascript most
of the time, I tend to find the Javascript Eventhandlers much more
elegant than the onload, but I can't tell you a reason.
By the way: The most recent API Doc is now using them as well, see for
example the Earth Plugin Introduction at
http://code.google.com/apis/earth/documentation/#using_the_google_earth_api.
Same is true for Google Maps.
If you're looking for real hard facts about why Javascript
Eventhandlers make more sense, I guess you could put up that the
approach is more universal, as these will work for everything inside
the DOM including every Javascript event itself, while HTML
Eventhandlers - per my understanding - only work for defined HTML
objects and defined events on these.
In addition it's a bit cleaner in your code, which comes in handy when
you're moving from a HTML-Javascript-Mixed Environment, where they're
equal partners in page design, to one where HTML really is just the
output-slave of everybody else, including Javascript.
Marco
On Oct 7, 4:26 am, fraser (Earth API Guru) wrote:
> Hi Nymor,
>
> The body onload action fires immediately after the browser loads the
> object it is attached to.
> The google.setOnLoadCallback method will call the specified callback
> function once your document (including any specified Google APIs) have
> finished loading.
> The main advantage of setOnLoadCallback as I see it is that it removes
> the functionality out of the HTML markup and gives a good catch all
> for all the Api.
>
> To use jquery as an example along with the plugin...
> --------------------------------------------------------------------------------------
> <script type="text/javascript"
> src="
http://www.google.com/jsapi"></script>
> <script type="text/javascript">
> google.load("jquery", "1");
> google.load("earth", "1");
> google.setOnLoadCallback(function() {
> // Place init code here instead of $(document).ready()
> });
> </script>
> ----------------------------------------------------------------------------------
>
> There is a good article on the benefits of this approach here:
http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-hos...