错误404页面表现得很疯狂

时间:2015-05-26 18:00:30

标签: javascript html

如果找不到文件,我正在使用.htaccess显示404页面。我使用javascript window.location来获取用户请求的页面并将其读取到页面上。但是页面一遍又一遍地加载。它是here。页面闪烁,拒绝加载。谁知道为什么?
HTML:

<h1 style="display:inline; font-family:crimson;">
  Sorry<span style="font-family:crimson;">,</span>
</h1> 
<h2 style="display:inline; font-family:crimson;">The page you requested: 
<span style="color:red">
<script>
var location = window.location;
document.write("<a href='" + location + "'>" + location + "</a>");
</script>
</span> was not on our site. That's all we know.</h2>

htaccess的:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule .* 404.html [L]
</IfModule>

1 个答案:

答案 0 :(得分:1)

您正在尝试声明一个名为location的变量,但由于该脚本位于全局范围内,因此该变量将映射到窗口对象window.location的现有成员,因此您实际上是做的是

var window.location = window.location;

这意味着您要分配到窗口位置,这会导致导航..只需重命名变量。

<script>
var sURL = window.location;
document.write("<a href='" + sURL+ "'>" + sURL+ "</a>");
</script>