Domanda

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?

È stato utile?

Soluzione

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:

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top