SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Method init()

  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Mumbai, Maharashtra, India
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Method init()

    Hello Everyone,

    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

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Gumape

  3. #3
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Mumbai, Maharashtra, India
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    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/5...nal-name-value

    http://sivuraide.blogspot.com/2007/0...ript-init.html

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

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).
    Gumape

  5. #5
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Mumbai, Maharashtra, India
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    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



    Sanjay Maurya


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •