开发者

Why does document.write() always cause the browsers tab to show the loading... indicator?

I have nothing on a page except the following:

<script type="text/javascript" 开发者_运维问答src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>

$(function() {

   document.write('foo');

});

<script>

When I run this page in firefox the loading indicator in the current browser tab seems to be in perpetual motion, never stopping. Why does this happen? Is it indicating that the document.write script runs ceaselessly?


You need to close the document after you've written to it:

document.write('foo');
document.close();

Otherwise the browser still has the document in an "open-for-writing" state, hence the loading indicator.

(Also, as @DaveRandom points out in his comment, you need close your <script> properly with </script>.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜