Jquery: Cancel button should take you back to the previous Url but if its the first page, take to Default url

302 Views Asked by At

I have a cancel button that should lead me to the previous url of my application. I have used:

if (window.history.length > 0) {
    window.history.back();
}
//If history.back is unsuccesful or no history exists
window.location.href = fallbackUrl;

This works ok. But what i need is that if I am coming from another url like google.com to my current page which has this cancel button(note: this has history), clicking "Cancel" should also call fallbackUrl and not history.back(). How is it possible?

0

There are 0 best solutions below