Ariana A
Ariana A

Reputation: 67

How to test the document.referrer on local?

I try to test the use of document.referrer in two local HTML pages but it doesn't work.

Here is my code:

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>

HTML2(123.html):

<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>

Does document.referrer work locally? How should I use it?

Upvotes: 0

Views: 2748

Answers (2)

Ariana A
Ariana A

Reputation: 67

Now I know why it can not work locally,because it relies on HTTP requests to work,

you can not use document.referrer even in an HTTP page jumped from an HTTPS page!

Upvotes: 0

pwxcoo
pwxcoo

Reputation: 3253

maybe cannot.

the document.referrer will be assigned by Browser and it will be stored by Browser.

The solution is that you could start a Quick Start web server.

Upvotes: 1

Related Questions