سؤال

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