HashChangeEvent oldURL Property - Javascript DOM

Javascript examples for DOM:HashChangeEvent

Description

The oldURL property returns the URL before the URL hash was changed.

To get the URL that was navigated to, use the newURL property.

This property is read-only.

Return Value

A String, representing the URL that was navigated from

When the hash has been changed, get the URL we navigated away from:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body onhashchange="myFunction(event)">

<button onclick="changePart()">Test</button>

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

<script>
function changePart() {/* ww w . java 2  s.  c om*/
    location.hash = "newHashValue";
}

function myFunction() {
    document.getElementById("demo").innerHTML = "Previous URL: " + event.oldURL + "<br>New URL: " + event.newURL;
}
</script>

</body>
</html>

Related Tutorials