【发布时间】:2014-09-13 23:13:44
【问题描述】:
我正在尝试使用 javascript 阻止 body 加载,然后在 body 元素上写一些东西。
我可以这样做:
<html>
<head>
<script>
document.write('<!--');
window.onload = function(){
document.body.innerHTML = "123";
}
</script>
</head>
<body>
<script>
alert(1); // This won't show
</script>
</body>
</html>
这行得通,永远不会调用alert 函数。
但问题是,如果head部分还有另一个注释标签,比如:
<html>
<head>
<script>
document.write('<!--');
window.onload = function(){
document.body.innerHTML = "123";
}
</script>
<!-- other tag -->
</head>
<body>
<script>
alert(1); // This will now show.
</script>
</body>
</html>
我应该如何处理?重要的是,body 元素上的所有内容都不会加载。不仅隐藏,还没有加载。
【问题讨论】:
-
保证这一点的唯一方法是不写出正文元素。例如,浏览器可能禁用了 JavaScript。
-
您有什么可能的理由这样做?这是你从未回答过的问题the last time you asked this。
-
从上面链接的副本已被删除。也就是说,这可能应该被认为是stackoverflow.com/questions/8943219/… 的副本。 (ping @kapa,你有没有机会编辑欺骗链接来修复它?)
标签: javascript html