gpt4 book ai didi

javascript - Firefox + 一些 javascript = 带有无限旋转轮的选项卡,永远不会完成加载(Chrome 还可以!)。为什么?

转载 作者:行者123 更新时间:2023-11-30 09:44:03 25 4
gpt4 key购买 nike

function clickMe() {
document.write("You clicked on the Button!");
}
<html>
<body>
<script src="script.js"></script>
<input type="button" value="Button" onclick="clickMe()" />
</body>
</html>

按下此处的按钮会导致 Firefox 选项卡加载轮永远旋转。这是为什么?

代码中是否有任何错误或者这可能是 Firefox 的问题?

非常感谢!

最佳答案

来自documentation

Writing to a document that has already loaded without calling document.open() will automatically perform a document.open call.

Once you have finished writing, it is recommended to call document.close(), to tell the browser to finish loading the page.

因此,每当您在已完成加载的文档上调用 document.write 时(就像使用事件处理程序一样),整个文档都会被覆盖,并且 document.open 会自动调用,但由于文档从未完成加载并调用 document.close,加载轮不断旋转。

显然不同的浏览器会做不同的事情,并且没有具体指定它们是否应该永远“挂起”。

由于 document.write 通常不应该被使用,这实际上不是一个问题,只需用修改 DOM 的正确方法替换它,而不是覆盖整个文档。

关于javascript - Firefox + 一些 javascript = 带有无限旋转轮的选项卡,永远不会完成加载(Chrome 还可以!)。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39738880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com