Hi I'm wondering if there is a way to give window.history.go(-1)
a default back page? If you enter a page directly from another site and someone clicks the back button, I don't want to direct them back to the referring site, I'd rather redirect them back to a search page within my application. I notice on some sites they are somehow reading the previous session, is that an option or no? Thanks
Asked
Active
Viewed 274 times
0

Code Junkie
- 7,602
- 26
- 79
- 141
-
Can't you just use a link that goes to a predetermined page on your website? I would probably try something like `Back` – Ian Hazzard Nov 13 '14 at 04:44
-
I have done something similar using history.js https://github.com/browserstate/history.js/ – ianaya89 Nov 13 '14 at 04:44
2 Answers
1
may be try something like this:
<a href="www.google.com" onclick="window.history.go(-1); return false;"> Back </a>

Suchit kumar
- 11,809
- 3
- 22
- 44
-
What does return false do? I had that in my code and it wasn't returning to my page. Once I removed it, everything seemed to work perfectly. – Code Junkie Nov 13 '14 at 05:03
-
-
-
Oddly enough return false actually causes it to return to the previous website and ignores the href page link. If I remove return false it works correctly hmm. – Code Junkie Nov 13 '14 at 05:16
-
I'm confused, your saying using false should prevent redirecting back to the previous website, but that seems not to work properly. False actually causes it to redirect back to the previous website when no history is present. Could you clarify. I don't want future readers to be miss informed. Thanks suchit. – Code Junkie Nov 13 '14 at 05:22
-
-
0
I think you might be interested in the window onbeforeunload event.
Have a look at this thread: using onbeforeunload event, url change on selecting stay on this page
-
Beware to use window onbeforeunload event, because most mobile browsers don't support this event. Instead use History API. [this](http://stackoverflow.com/questions/6205989/is-there-an-alternative-method-to-use-onbeforeunload-in-mobile-safari) will help. – Domain Nov 13 '14 at 06:57