). ?
....
....
<
-
IE doesn't allow this anymore (since Version 10, I believe) and will ignore such scripts. FF and Chrome still tolerate them, but there are chances that some day they will drop this as non-standard.
讨论(0)
-
Yes. Only comments and the end tag for the html element are allowed after the end tag for the body.
Browsers may perform error recovery, but you should never depend on that.
讨论(0)
-
Yes. But if you do add the code outside it most likely will not be the end of the world since most browsers will fix it, but it is still a bad practice to get into.
讨论(0)
-
As Andy said the document will be not valid, but nevertheless the script will still be interpreted. See the snippet from WebKit for example:
void HTMLParser::processCloseTag(Token* t)
{
// Support for really broken html.
// we never close the body tag, since some stupid web pages close it before
// the actual end of the doc.
// let's rely on the end() call to close things.
if (t->tagName == htmlTag || t->tagName == bodyTag
|| t->tagName == commentAtom)
return;
...
讨论(0)
-
Modern browsers will take script tags in the body like so:
<body>
<script src="scripts/main.js"></script>
</body>
Basically, it means that the script will be loaded once the page has finished, which may be useful in certain cases (namely DOM manipulation). However, I highly recommend you take the same script and put it in the head tag with "defer", as it will give the same effect.
<head>
<script src="scripts/main.js" defer></script>
</head>
讨论(0)
-
It won't validate outside of the <body>
or <head>
tags. It also won't make much difference — unless you're doing DOM manipulations that could break IE before the body element is fully loaded — to putting it just before the closing </body>
.
<html>
....
<body>
....
<script type="text/javascript" src="theJs.js"></script>
</body>
</html>
讨论(0)
- 热议问题