How to get previous page URL using jQuery ~ MiTechDev.com

Mitechdev.com is a programming blog which focused on Web Programming and development

Friday, 1 July 2016

How to get previous page URL using jQuery

02:19:00 Posted by raviteja swayampu , No comments
We can get a previous page URL in jquery using a single property 'referer'.This is document object property.It returns the document URL of the previous page that loaded the current page.
Check the code below
$(document).ready(function(){
   var referer=document.referrer;
});
This is supported by all major browsers.But there is a small problem with the property 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;
  }
});
It is a small tip from me.I used it in my project.i will share many more tips like this in future for real time development.I will come with another tip later..

0 comments:

Post a Comment