You can use a regex of /\/success(\/|$)/
to test this:
if (/\/success(\/|$)/.test(window.location.href)) {
console.log('Yep, it has success');
} else {
console.log('Nope - no success');
}
This will accept /success/
anywhere in the string and would match:
http://xxxxxxxxx:8000/compare/387552/1/389688/1/success
http://xxxxxxxxx:8000/compare/387552/1/389688/success/1
http://xxxxxxxxx:8000/compare/387552/1/success/389688/1
http://xxxxxxxxx:8000/compare/success/387552/1/389688/1
http://xxxxxxxxx:8000/success/compare/387552/1/389688/1
If you only want to match success and the end of the URL, you should use /\/success\/?$/
:
if (/\/success\/?$/.test(window.location.href)) {
console.log('Yep, it has success');
} else {
console.log('Nope - no success');
}
Which will only match:
http://xxxxxxxxx:8000/compare/387552/1/389688/1/success
http://xxxxxxxxx:8000/compare/387552/1/389688/1/success/