HashChangeEvent newURL Property - Javascript DOM

Javascript examples for DOM:HashChangeEvent

Description

The newURL property returns the URL of the document, after the URL hash has been changed.

To get the URL that was navigated away from, use the oldURL property.

This property is read-only.

Return Value

A String, representing the URL that is navigated to

When the hash has been changed, get the URL we are navigating to:

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() {//from ww w. jav  a2 s  .  c  o  m
    location.hash = "newHashValue";
}

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

</body>
</html>

Related Tutorials