Window.location redirection works, but the original URL does not appear in browser history

The code below works well. Here is my problem: redirecting window urls, but the source url is not registered in my browser history.

For example, if I find "http://example.com/page1", the browser is redirected to "http://example.com/test", as it should be. However, I need the original visitor url ("http://example.com/page1") so that it appears in my browser history so that I can call it in another function.

In any case, in order to get the original URL that I visited in order to go into my browser history before redirecting?

<!-- script to enable age verification cookies and ensure people have age checked --> <script type="text/javascript"> $(document).ready(function(){ if (window.location =="http://example.com/home") {//do nothing } else { window.location = "http://example.com/test"; } }); </script> 
+7
source share
1 answer

I think you need window.location.href . This adds the previous URL to your browser history.

+2
source

All Articles