tags:

views:

176

answers:

3

heya,

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

A: 

Try:

 location.replace(www.google.com');

This should put the page in your history.

Alex
That replaces the current item with the new page, removing the old one. That's more of a redirect.
Improfane
+2  A: 
SolutionYogi
+1  A: 

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

Orr Siloni