2

I am able to get the previous page URL, but also I need to get the URL of the second last visited page.

I have used the below code..

<script>
_spBodyOnLoadFunctionNames.push("GetUrl");  

function GetUrl() {
   var referrer =  document.referrer;
alert(referrer);

//var x=history.go(-2);
//alert(x);
}
</script>

but history.go(-2) will directly redirect to the second last visited page, how to get that url?

2
  • I am able to get the previous page URL, but also I need to get the URL of the second last visited page. I have used the below code.. <script> _spBodyOnLoadFunctionNames.push("GetUrl"); function GetUrl() { var referrer = document.referrer; alert(referrer); //var x=history.go(-2); //alert(x); } </script> but > history.go(-2) will directly redirect to the second last visited page, how to get that url?
    – B upender
    Commented Oct 13, 2019 at 6:20
  • I am able to get the previous page URL, but also I need to get the URL of the second last visited page. I have used the below code..
    – B upender
    Commented Oct 13, 2019 at 6:22

2 Answers 2

1

this worked for me..

<script>
_spBodyOnLoadFunctionNames.push("GetUrl");  

function GetUrl() {
   var referrer =  document.referrer;
//alert(referrer);
}

function SecondLast(){
var x=history.go(-2);
//alert(x);
}


</script>
<button onclick="SecondLast()">Click me</button>
3
  • Does it prevent you from redirecting? Commented Nov 10, 2015 at 11:59
  • no, but now I can do it on button click..
    – KumarV
    Commented Nov 12, 2015 at 5:07
  • In your question you asked that "how to get that url". redirecting in button click was not your requirement Commented Nov 12, 2015 at 5:10
1

In general history is protected by the browser against javascript accessing it except through back and forward functionality.

https://stackoverflow.com/questions/13369829/access-my-entire-browsing-history-via-javascript

So you can not access it.

2
  • 5
    If you have JS access to all pages store the URL in a cookie Commented Nov 10, 2015 at 11:20
  • Excellent alternative solution! @DannyEngelman Commented Nov 10, 2015 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.