- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 JavaScript 代码中运行了一些 while 循环,并且很好奇是什么导致循环从网站中删除了所有代码(除了单个 header )。我认为这是因为循环是无限的(因为 1 总是等于 1),但很好奇为什么它不只是让网站崩溃。是不是因为document.write没有指定到某个路径?
javascript: (function() { while (1) { document.write('Y'); }})();
编辑:感谢您的帮助,似乎 document.open 已运行并导致页面代码被删除。然后浏览器认为这是由于实际网站的代码造成的,Chrome 发出了一条错误消息。
最佳答案
document.write()
是一个DOM阻塞函数,也就是说,浏览器会中断解析。因此,当您的函数被调用时,浏览器将永远停留在该函数上,并且无法继续正确渲染网站。
另一个效果如下:
as document.write writes to the document stream, calling document.write on a closed (loaded) document automatically calls document.open, which will clear the document.
https://developer.mozilla.org/en-US/docs/Web/API/Document/write
两者都取决于时间并且可能涉及竞争条件。
请阅读此问答以获取有关 SO 的更多信息:
关于javascript - 是什么导致 While (1) 循环删除网站的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56006758/
我是一名优秀的程序员,十分优秀!