Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript history.back not working

Tags:

javascript

I built a facebook tab which has a form to fill out. However below the form there is a link to a terms and conditions page which sits on a different URL from the form.

The form is on: page/like and the T&C page is on page/terms

In the T7C page there is a back button which inside the href has the following:

 href="javascript:window.history.back()"

and this button suppose to bring you back to the form after you have red the T&C.

This works fine on a testing server, however as soon as it's embedded in facebook the back button stops working and it doesn't go back to the form but to the home page of the brand.

The other issue that I have just came across is the if I fill out some of the fields and then I click on the T&C page and go back to the form using the back button the input fields are all empty.

Is there a way front-end side that this can be fixed too?

like image 752
Aessandro Avatar asked Jul 17 '26 13:07

Aessandro


2 Answers

Does the console tell you anything?

Try window.history.go(-1);.

Alternatively, have you tried opening the T&C in a separate window using target="_blank"? If you are worried about making sure the terms are read, inside the opened window, you may be able to run a function in the parent window using window.opener.readTC(), where .readTC is your function.

like image 53
Julian H. Lam Avatar answered Jul 20 '26 01:07

Julian H. Lam


You can wrap this in a button:

<button type="button" onclick="window.history.go(-1)">Go back</button>
like image 36
Peko Avatar answered Jul 20 '26 02:07

Peko