Method init()

Hello Everyone, :slight_smile:

Could anyone please help me on method init()? How does it work?

What is difference between onload and init methods? Please give an example where onload fails to load script and init works instead. What is syntax of using it? Please include examples for both IE and FF.

If you could just provide me very detailed tutorial or name of book on the init method and its uses, it would be great help. Could you please guide me on this regard?

Thank you :slight_smile:

hi,

you are right, the name of โ€˜initโ€™ is used as a standard function name for initialization. For example, when a function is registered to listen the onload event, its name is usually โ€˜initโ€™ (javascript.about.com) and the constructor or initialization methods of objects are usually called as โ€˜initโ€™ (stackoverflow).

Thank you Gumape. Thanks for looking into it.
I had read some tutorials and pdf on JavaScript. They all had mentioned method init() in their description. But they never explained that init() is not built in JavaScript method.

Is init() used as standard function name for initialization?

Please see the below examples/links where the confusion aroused.

http://stackoverflow.com/questions/513466/creating-a-object-in-javascript-that-has-a-init-method-with-optional-name-value

http://javascript.about.com/library/blonload.htm

Thank you so much Gumape!!! That was a lot help on this topic, Gumape. Everything is clear to me now on init().

Lots of smiles for you from my end

:):):):):):D:D:D:D:cool::cool::cool::cool: :afro: :afro::flippy::flippy::nanaman::nanaman:

Sanjay Maurya

The onload event occurs when an object has been loaded. The onload event for the body (or window) fires after all objects in the DOM hierarchy (images, โ€ฆ) have finished loading and the document object has been built up. At that point, you can access the elements of the document (such as getElementById, getElementsByName), you can manipulate the contents of the document, etc.

There are some other events related to the onload event: onreadystatechange, DOMContentLoaded, onbeforeunload, onunload.

For further details and examples please see the following page:
onload event.

P.S. There is no event or method named โ€˜initโ€™ in JavaScript.