Javascript history.back not working - Stack Overflow

I built a facebook tab which has a form to fill out. However below the form there is a link to a terms

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?

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?

Share Improve this question edited Jun 7, 2013 at 14:58 Aessandro asked Jun 7, 2013 at 14:17 AessandroAessandro 5,77121 gold badges72 silver badges146 bronze badges 1
  • its possible that the anchor click is causing the history to increment by one. (just a hunch) – DevZer0 Commented Jun 7, 2013 at 14:20
Add a ment  | 

3 Answers 3

Reset to default 3

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.

You can wrap this in a button:

<button type="button" onclick="window.history.go(-1)">Go back</button>

Try this example...

<html>
<head>
<script>
function goBack()
  {
  window.history.back()
  }
</script>
</head>
<body>

<input type="button" value="Back" onclick="goBack()">

</body>
</html>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742332903a4424075.html

相关推荐

  • Javascript history.back not working - Stack Overflow

    I built a facebook tab which has a form to fill out. However below the form there is a link to a terms

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信