Search code examples
javascriptbrowser-history

How to prevent history.back() from going back to login page


I have a back button in my application which on click should return to parent page. I am using history.back() for the purpose . However I am not able to prevent it from going back to login.


Solution

  • Use the document.referrer to check the previous clicked link :

    if(document.referrer !="http://myloginpage"){ // different then the url login then go back 
       window.history.back()
    }