How to get previous page URL using jQuery

jQuery code to get the previous page URL. The referrer property returns the URL of the document that loaded the current document.
$(document).ready(function() {
   var referrer =  document.referrer;
});
The referrer property is supported in all major browsers. But there is a problem here. It is quite possible that Page URL is shared through social media, email or accessed using direct link. So in that case, there is no referrer.
$(document).ready(function() {
  if(document.referrer.indexOf(window.location.hostname) != -1){
     var referrer =  document.referrer;
  }
});
Feel free to contact me for any help related to jQuery, I will gladly help you.
SHARE

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..