最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Loading script outside of html document - Stack Overflow

programmeradmin6浏览0评论

I came accross this html snippet & to my surprise jQuery Object does get created!

<!doctype html>
<body>
<h1>Hello World</h1>
</body>
</html>
<script src=".5.1/jquery.js"></script>

As you may notice <script> tag es AFTER closing </html> tag. I wonder how & why does this even work?

I came accross this html snippet & to my surprise jQuery Object does get created!

<!doctype html>
<body>
<h1>Hello World</h1>
</body>
</html>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.5.1/jquery.js"></script>

As you may notice <script> tag es AFTER closing </html> tag. I wonder how & why does this even work?

Share Improve this question asked Aug 1, 2011 at 8:27 CuriousMindCuriousMind 34.2k29 gold badges100 silver badges141 bronze badges 2
  • 2 Browsers are very error tolerant. They have to be, you'd be lucky to find a single strictly standards pliant page on the Internet. – JJJ Commented Aug 1, 2011 at 8:31
  • try your code on ie6 or 7 and see the result :p – Awea Commented Aug 1, 2011 at 8:32
Add a ment  | 

3 Answers 3

Reset to default 8

It works because browsers are very forgiving, there is no benefit to doing it this way.

The reason it is there, is probably because someone misunderstood what was meant by 'putting scripts as far down the page as possible'…

If you validate the file, it would say it is not valid. However, browsers will usualy try and do things the way you probably meant them.

Browsers just aren't that strict. You can do alot of things wrong and they would still work.

I checked this code for firefox , script is treated as inside body tag for this particular case .

Browsers are really Error tolerant indeed .

发布评论

评论列表(0)

  1. 暂无评论