The code I've included below is meant to redirect to a new url if the user is not on a specific page or does not have a certain cookie. The cookie function works perfectly as does the redirect. Here is my problem: The window url redirects, but the original url is not logged in my browser history.
<script type="text/javascript">
$(document).ready(function() {
if (getCookie('legal_age') == "yes" || window.location =="http://example.com/home") {//user is legal age!
} else {
setTimeout(function() {
window.open('http://example.com/welcome','_self','', false);
},0)
}
});
</script>
For example, if I visit "http://example.com/page1", the browser redirects to "http://example.com/welcome", as it should. However, I need the original url visited ("http://example.com/page1") to show up in my browser history so that I can call upon it in a different function. Here is the code I am using to call the history (within a form):
<form action="javascript:window.location.reload(history.go(-1));" method="get" name="age_form" id="ageForm" />
I've also tried this alternative to call the history and it didn't help:
window.history.back();
I have also tried the following with no success in saving original url in browser history:
window.location = "http://example.com/welcome";
window.location.href = "http://example.com/welcome";
window.location.assign("http://example.com/welcome");
Finally, I included this function because another thread suggested it might help, but it hasn't seemed to do much:
setTimeout(function(){
Any ideas? Is there anyway to get the original url visited to log in my browser's history before redirecting? HELP please!