jQuery – Back button that prevent going out from site

December 7th, 2016

jQuery’s script that, on click on defined element, check if the previous url in browser memory, is inner the defined domain or not.
If is in defined domain, navigate to the previous pag, else, bring browser to the home page

jQuery( ".bck_btn" ).click(function( event ) { // Define the element
var referrer = document.referrer; // Retrive last url in browser memory
var term = 'luxury'; // Define domain of the site
if ( referrer.indexOf( term ) != -1 ) { // Check if we are inside our main domain or not
window.location.replace(referrer); // navigate to previous page
window.location.replace('http://immobiliarepercassi.beprime.it/luxury/'); // else navigate to home page