<head> or <body> section - javascript

hi there,

when i put a javascript in the property of a screen, is it put in the head section or body section of the web page? If in the body section, how to put it in the head section? And what is the difference to put it in the head or in the body?



I think it's in the head.
There is no real difference, if you code html/javascript yourself you would probably do it for tidyness.

There is a difference however in placing javascript in the head or the foot.
Placing it on the foot will make it load after the page has been rendered, which would be fine for background stuff, anything that does something with the UI should be placed on top instead.



Claring, you are "almost" right.

The JavaScript set into page property will be saved to an external file and loaded by the browser when it is rendering the HEAD, as the platform will put a <scrip> tag in the HEAD to load the file.

Said that, this script will run before the DOM is complete (and before the BODY even begins to be rendered).

If you put the JavaScript in an EXPRESSION (using the Escape Content set to NO), than your script will run when the browser reach that expression during the render of the BODY of the page. Again, usually, you will have access ONLY to elements in the body that are already rendered. This is the reason why a ToolTip must be placed AFTER the element to where it is attached, for example.

There are ways to execute JavaScript code ONLY when the entire document is ready, of course, for both situations.

The JavaScript being in the Page Header, the Page Main Content or the Page Footer will be loaded differently if they are in the JavaScript property (will be loaded by script tag in HEAD of the file) or in an expression (will be executed at the moment the browser find them in the BODY of the document).

Eduardo Jauch


Thank you Claring and Jauch.. you rock!

That was very helpful...