1

I'm stumped with a very simple question. Since the <body> tag always precedes content, when does body onload execute; at the opening tag or at the closing tag? Can body onload advance to a point where it ignores code inside of it?
And so then maybe I skipped this part at the very basics of coding... If I open a tag with say, a style property, and don't close it, will it still execute?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Manny Alvarado
  • 1,135
  • 9
  • 14
  • Does this answer your question: http://stackoverflow.com/questions/10494620/when-does-a-body-onload-gets-called ? – Ioan-Radu Tanasescu Jan 20 '16 at 12:33
  • The fact that things are serialized in a certain order in the HTML source, doesn't mean that they are executed in that order. The `body` element is one element, delimited by the `` and `` start and end tags, and the `on...` attributes apply to the whole body, not just the start tag. – Mr Lister Jan 25 '16 at 11:54

1 Answers1

0

Body itself is the content of your page, no pre-loading as such..

So if you run an onload event, this will trigger once the content of your body is ready and generally has rendered itself or is about to.

In general, you would create any content within the body tag or using a script at run time and then run a onload script to finalise everything.. This could be use to add javascript hover effects or to hide a progress bar for loading.. Generally once that script is done. The page should be ready for the user.

Code will never be ignored ever (with exception to crashes/cancelled requests), But it depends if the code is taking effect like it should.. You element might not be ready if your adding it dynamically..

Another big issue to watch out for while developing is cache, this is a nasty creature that will waste hours of your time...And last but not least, use the browser console to debug at various points and test what is happening.

As for closing tags, If you mean you you do not put the > character at the end, it will break the page.. In the case of tag like link.. But for a script, you must close it upto the point of the < /script > tag

Angry 84
  • 2,935
  • 1
  • 25
  • 24
  • 1
    Yeah `cache` is very painful sometime. – Gaurav Gandhi Jan 20 '16 at 12:46
  • Cache is very useful if you have a slow connection. It can save hours of downloading time! Anyway, if you put errors in your HMTL page, you are at the mercy of the browsers error handling routines. Now _those_ are nasty! – Mr Lister Jan 25 '16 at 11:56
  • All developers should have caching disabled until it is released live and tested. I generally development within a gigabit connection to the hosting server. Otherwise enabling cache for only certain filetypes, having a easy config switch or other means to enable it when your in doubt of some bug – Angry 84 Jan 27 '16 at 03:21
  • Thanks Mayhem. Very well explained. This stems for an issue in a webapp I have developed where body onload redirects (window.location) to a "form submitted" page, after a phpmailer script runs. I'm just having issues where the form doesn't get submitted, and thought it was the onload window.location javascript. – Manny Alvarado Feb 04 '16 at 12:08
  • Have you been able to resolve your issue or is it still present? – Angry 84 Feb 04 '16 at 22:14
  • Sorry about that. I actually went on to divide the final file into two separate files: one renders the email and sends it and redirects to another file that shows a message "form submitted". I'm still wary about whether the browser is too fast as to forget it "filled in" data when it comes to get a value from a $_POST... I'll research php debugging later on. Thanks again! – Manny Alvarado Feb 10 '16 at 19:36
  • example code always helps, if you can produce a small example... Can try and help further – Angry 84 Feb 10 '16 at 23:06