I'm attempting to use document.location(.href) on the onLoad event to redirect from one page (A) to another (B).
From my understanding, if I use document.location.href (as opposed to .replace), it should add (A) to my history. However, this doesn't appear to be happening.
I've tried setting document.location, document.location.href, and using .assign, and none of these seem to add the first page to the history. Is there any JS technique that can be done via onLoad that will cause (A) to be in the history?
Cheers, Victor
'location.href', 'document.location' or any of these variations will only add an entry to the browser history if it came from a user initiated action. For example, if user clicks a button that fires a function that performs a 'location.href' it will be added to browser history, but if 'location.href' is called by an onload event - which is not a user initiated action, it will not be added to the history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With