In footers-extras.php
<script>
var ref=window.location.href;
if (ref.includes('index.php') == 0 && $j('.navbar-text').not('.navbar-right').length == 0) {
localStorage.setItem('redirecturl', ref);
}
else {
if ($j('.navbar-text').length != 0 && ref.includes('index.php') != 0 && localStorage.hasOwnProperty("redirecturl")) {
ref=localStorage.getItem('redirecturl');
localStorage.removeItem('redirecturl');
$j(location).attr('href', ref);
}
}
</script>