Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.location - Not adding to history

Tags:

javascript

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

like image 304
victorhooi Avatar asked Oct 19 '25 01:10

victorhooi


1 Answers

'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.

like image 154
Orr Siloni Avatar answered Oct 22 '25 05:10

Orr Siloni