Javascript 如何在本地对文档进行测试?

Javascript 如何在本地对文档进行测试?,javascript,html,dom,Javascript,Html,Dom,我尝试在两个本地HTML页面中测试document.referer的使用,但它不起作用 这是我的密码: HTML1: <body> <button type="button" name="button" onclick="go()">go!</button> <a href="123.html">go with a</a> </body> <script type="text/javascript">

我尝试在两个本地HTML页面中测试
document.referer
的使用,但它不起作用

这是我的密码:

HTML1:

<body>
  <button type="button" name="button" onclick="go()">go!</button>
  <a href="123.html">go with a</a>
</body>
<script type="text/javascript">
  function go() {
    location.assign('123.html')
  }
</script>

去
函数go(){
location.assign('123.html')
}
HTML2(123.html):


返回
函数gopre(){
地点。分配(文件。推荐人);
//console.log(document.referer);//为空
}
文档推荐人是否在本地工作?我应该如何使用它?

也许不能

文档。引用者将由浏览器分配,并由浏览器存储


解决方案是您可以启动一个
快速启动
web服务器。

现在我知道为什么它不能在本地工作,因为它依赖HTTP请求工作

您不能使用
文档。即使在从HTTPS页面跳转的HTTP页面中,也不能使用referer

<body>
  <button type="button" name="button" onclick="gopre()">back</button>
</body>
<script type="text/javascript">
  function gopre() {
    location.assign(document.referrer);
    //console.log(document.referrer);//it's null
  }
</script>