How to check if referring URL contains a particular segment?

How can I check if the referring URL contains /checkout/ in the second segment? I want a 'Continue Shopping' button to link differently depending on the previous page the customer has visited. I'd like to check if the customer has returned to the 'cart' page from the 'checkout' page. Checkout page url looks like: 'mysite.com.au/checkouts/au/xyz' I need to check to see if the referrer url contains 'checkout'. Here is what I've tried. if (document.referrer.indexOf("checkouts") > -1) { $('.js-back').on('click', function(evt) { //evt.preventDefault(); //history.go(-2); alert("cart found"); console.log('It works'); }); } else { $('.js-back').on('click', function(evt) { // evt.preventDefault(); //history.go(-1); alert("not found"); console.log('It not works'); }); }

Comment (0)

You’ll be in good company