Javascript Reference - HTML DOM referrer Property








The referrer property returns the URL of the document that loaded the current document.

Browser Support

referrer Yes Yes Yes Yes Yes

Syntax

document.referrer

Return Value

A String type value containing the URL that loaded the current document.





Example

The following code shows how to get the referrer of the current document.


<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction(){<!--from   www.j a  v a2s.c om-->
    var x = document.getElementById("demo");
    x.innerHTML=document.referrer;
}
</script>

</body>
</html>

The code above is rendered as follows: