Reputation: 262
I have written JavaScript for back button like this and my HTML is
<a onclick="goBack()" href="javascript:">
and
function goBack() {
window.history.back(1);
}
my path is:
home-> page A -> Page B
its works fine when i try to redirect from page B to A works perfect but issue is than when i click on back button on page A than its take me to page B not on home page.
So how can I resolve this issue? how it can store history????
Upvotes: 1
Views: 380
Reputation: 262
I have put history.go(-1) its working on after proper build of app. so for if any has issue like i had so my suggestion is that please proper build your application. its working and some how its also doesn't support while you do test on browser.
Upvotes: 0
Reputation:
History doesn't work exactly the way you seem to think. When you navigate (or redirect) to a new page, the new page is added to the history, even if it already exists earlier in the history. In other words, the browser does not search for the new page in the history and assume you really wanted to go back there; instead, the new page gets added to the history. So:
ACTION HISTORY
============================
start at home home
navigate to A home A
navigate to B home A B
redirect to A home A B A <=== A is added to history
back home A B A
^
So, the back
puts you back on B
, as expected.
By the way, back
is just back
with no parameter. You may want history.go
. But that is not your problem.
Upvotes: 1