Document referrer Property - Javascript DOM

Javascript examples for DOM:Document referrer

Description

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

Return Value

A String, representing the URL of the document that loaded the current document.

If the current document was not opened through a link (for example, via a bookmark), an empty string is returned.

The following code shows how to return the referrer of the current document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {//  w  w  w.jav a 2s.co m
    var x = document.referrer;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials