Is it wrong to place <script> tag after </body> tag?
P粉654894952
P粉654894952 2023-08-21 23:56:17
0
2
477
<p>How wrong is it to put a script tag after the closing body tag (<code></body></code>)? </p> <pre class="brush:php;toolbar:false;"><html> .... <body> .... </body> <script type="text/javascript" src="theJs.js"></script> </html></pre>
P粉654894952
P粉654894952

reply all(2)
P粉073857911

After the body closing tag, only comments and closing tags of html elements are allowed to be added.

You can confirm via Specification or Validator.

Browsers may perform error recovery, and the HTML specification even describes how to recover in this case, but you should never rely on this.


With the advent of the defer attribute, we can place script inside

and get this benefit while also having the browser download the HTML in parallel to Improve performance.
P粉232409069

It will not validate outside of the <body> or <head> tags. It also doesn't make much of a difference unless you're doing DOM manipulation before the

element is fully loaded which might break IE - put it before closing the .
<html>
  ....
  <body>
     ....
     <script type="text/javascript" src="theJs.js"></script>
  </body>
</html>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!