Using this code, it cannot provide the last history item correctly, instead it displayed undefined:

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

What is the correct code to retrieve the last history item's URL?

有帮助吗?

解决方案

You may use the document.referrer to view the last page history instead of using the history object.

Also to note that history.previous property is not available to web content and is not supported by other browsers and it is obsolete.

You may check these references:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top