最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I keep form data when Back button is clicked - Stack Overflow

programmeradmin6浏览0评论

I am developing a rails app. (I don't think this is a rails-specific problem) There's a reservation process which is consisted of 3 steps. When a user is on step 2 page, if the user clicks 'Previous' button, the form data in step 1 should be the same as before.

I attached "history.go(-1);" to the 'Previous' button.

It works on my firefox browser. But it doesn't work on some IE browsers. My IE works though.

How can I force it to preserve the form data when the page is back?

Thanks.

Sam

I am developing a rails app. (I don't think this is a rails-specific problem) There's a reservation process which is consisted of 3 steps. When a user is on step 2 page, if the user clicks 'Previous' button, the form data in step 1 should be the same as before.

I attached "history.go(-1);" to the 'Previous' button.

It works on my firefox browser. But it doesn't work on some IE browsers. My IE works though.

How can I force it to preserve the form data when the page is back?

Thanks.

Sam

Share Improve this question asked Jun 22, 2009 at 21:24 Sam KongSam Kong 5,8409 gold badges53 silver badges87 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Can't rely on the client (javascript) for this kind of operation.

You save the data somewhere at step 1, so just restore it.

look into having a hidden iframe on the page to store the data. I am not sure of the specifics of implementing this, but this is the technique people use to store the state of the page when the hash changes in the URL. Check if some libraries like dojo and jquery help support this situation.

You could save page 2's data to the database, or a server-memory cache, or a cookie or three, and restore it when the page is loaded.

ASP.NET does this automatically via ViewState (note: article is ancient, but still quite accurate). Perhaps you can adapt a similiar approach to Rails.

发布评论

评论列表(0)

  1. 暂无评论