SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: body onLoad()

  1. #1
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    body onLoad()

    Just wondering if anyone knows if it's bad practice to put multiple body tags within one document? I'm using a template system (php) that loads template files into a main template (already containing a body onLoad()), and the content files also have a body onLoad() preloading functions intact. It seems to be working but wanted to know if there is anything wrong with this? What about broswer specific issues?

    Thanks!

    Matt

  2. #2
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please clarify. Are you asking if it is okay to use multiple <body></body> tags or are you asking if it is okay to use multiple onLoad events?

    Multiple <body></body> tags would not be proper.
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  3. #3
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm asking if it's ok to use both! Two body tags, each with an onLoad().

    Thanks!

    Matt

  4. #4
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No it is not okay. Instead of using the "onLoad=" within a second body tag, use the following within the header area:
    Code:
    <script language="JavaScript" type="text/javascript" ><!--
    window.onload=functionname;
    //--></script>
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  5. #5
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KLB
    No it is not okay. Instead of using the "onLoad=" within a second body tag, use the following within the header area:
    Code:
    <script language="JavaScript" type="text/javascript" ><!--
    window.onload=functionname;
    //--></script>
    OK so this is what I have in my sub template file for the function call using the above script:

    window.onload="MM_preloadImages('/images/products/photo_set_f5.jpg')";

    And it seems to be working fine. Does it matter if this template/content document *doesn't* have a head tag? It's only a simple table with images etc... So the above script is located at the top of the file, above the content. The content file (template) gets dynamically 'paisted' into the main document file, which contains the body/onLoad tag.

    Is this the way that you thought it was set up?

    Thanks for your help!

    Matt

  6. #6
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can get answers to these questions and more at:
    http://www.w3schools.com/default.asp
    http://www.w3c.org/

  7. #7
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't have a header section, putting the script within the body area should do just fine. At the bare minimum, any HTML output should have the following structure:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    	<title></title>
    	<meta name="language" content="en-US">
    	<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    </head>
    <body></body>
    </html>
    "Content-Type" is the character set being used; "language" is the language the spoken language the document is written in; and "DOCTYPE" is the HTML/XHTML specification the document is written to.
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space


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
  •