You can do it several ways:
// Javascript directly in the href
<a href="javascript: history.go(-1)">Go Back</a>
another way would be:
// onclick Method
<a href="#" onClick="history.go(-1); return false;">Go back</a>
Or as mentioned above my post
// windows method
javascript:window.history.back();
and for last you can create a function
<script>
function goBack() {
history.go(-1);
}
</script>
<button onclick="goBack()">Go Back</button>
If you want to have it done automatically you just need to use it in a function and add a setTimeout:
function goBackTimed() {
setTimeout(() => {
window.history.go(-1);
}, 3000);
}
Since your using WordPress, I would recommend doing this using the functions.php file and add a filter with a function for the redirect, but since you requested how to do this with javascript, you need to inspect your thank you page to grab the page-id-[ID-NUMBER] class it generates on the body tag your script above would need a condition to detect if the class is present on the body assuming this script is loaded on your entire site:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
//location = 'abc.com1/thank-you/';
if ( '17615' == event.detail.contactFormId ) {
}
else if( '19110' == event.detail.contactFormId ){
location = 'abc.com1/thank-you-broucher/';
}
else {
location = 'abc.com1/thank-you/';
}
}, false );
if (document.body.classList.contains('page-id-12345')) {
function goBack() {
history.go(-1);
}
window.setInterval(goBack, 3000);
}
</script>
I prefer history.go(); since you can go back even more than 1 page back for example history.go(-2); would go back 2 pages instead of one, this sometimes can be handy in certain cases.