Failed to get latest javascript history

Using this code, it cannot provide the last element of the story correctly, instead it displays undefined:

<input type="button" onclick="getHistoryLast()" value="test">
<script>
function getHistoryLast(){
    var x=history.previous;
    alert(x);
}
</script>

What is the correct code to get the last url of a story item?

+4
source share
1 answer

You can use document.referrerto view the history of the last page instead of using the object history.

It should also be noted that the property is history.previousnot available for web content and is not supported by other browsers, and it is deprecated.

You can check these links:

+4

Source: https://habr.com/ru/post/1530576/


All Articles