tags:

views:

807

answers:

9

Our security manager (Tivoli Access Manager, TAM) dynamically inserts a bit of javascript at the top of every html page when requested. It is inserted above the DOCTYPE statement. I think this might be the cause of the layout problems I am having.

Ideas anyone?

+3  A: 

Yes, the DOCTYPE must come first.

The definition is here: http://www.w3.org/TR/REC-html40/struct/global.html. Note that it says a document consists of three parts, and the DTD must be first.

Brad Wilson
+9  A: 

Yes, DOCTYPE must be the first data on the page: http://www.w3schools.com/tags/tag_DOCTYPE.asp

erlando
Could you link to W3C as reference? W3schools isn't affiliated with W3C, isn't authoritative source on the subject, and sometimes their information is wrong (but they're OK in this case).
porneL
+1  A: 

It could be the source of your problem though! Check out "quirks mode" as that depends on doctype settings. Further study : http://www.quirksmode.org/ explanation: you can toggle your browser into (mostly IE) strict standards compilant mode, and loose mode. This will greatly affect rendering. TAM's setting could have switched this on/off.

A: 

I read the w3 specs which just say that there are 3 parts to a document. The sequence is assumed and there is no explicit statement forbidding, for example, a little js snippit up front.

I understand that it is possible to configure TAM to add the js at the end of the dicument but it beats me why they put it up top if it can cause such obvious problems!

paul
`<script>` tags aren't permitted outside of the <html> page, but if your only options are before or after you should probably choose after, as it will have fewer side effects.
Jeremy Banks
A: 

I think the more important question is why do you need JS snippet on the top of the page? why cannot it go within the 'head' tag just as it normally does?

TAM inserts the js on-the-fly and part of its security job. The default is the top of the page. Guess it's easier for them to do that than to find the head tag and insert it there.
paul
A: 

The recommendation for HTML expresses it as an application of SGML, which requires that the DOCTYPE declaration appear before the HTML element (ignoring HTML comments). Even without the DOCTYPE, adding a SCRIPT element outside the HTML element (either before it or after it) is not valid HTML. Of course, HTML validity may not be a requirement for you, so long as it works in most browsers, and then the quirks-mode switching mentioned will get you: without the DOCTYPE, many browsers will switch to quirks mode, possibly changing the layout.

I assume the TAM script fragment is being added by some proxy or other which is not able to properly analyse the HTML structure of the page and insert the SCRIPT in the correct position in the HEAD or BODY of the document. In this case, adding to the end of the document, while not valid HTML, will work in most web browsers.

pdc
A: 

<script> tags aren't permitted outside of the <html> page, but if your only options are before or after you should probably choose after, as it will have fewer side effects.

Jeremy Banks
+1  A: 

I too faced the same issue... solution is at this URL: http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.itame.doc/am61_webseal_admin585.htm

A: 

It’s not a tag, but yup. Mainly because that’s the only way to get Internet Explorer (pre-version 8, I think) into standards mode.

Paul D. Waite