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

javascript - Browser back button and dynamic elements - Stack Overflow

programmeradmin0浏览0评论

I have a page that uses jQuery to create a number of <input> DOM elements dynamically based on what user picks from a <select> box.

Let's say the user picks 4 from the select box, my script dynamically shows 4 input boxes.

The problem is when the user refreshes or goes back to this page (with the browser back button). The elements that are created dynamically are not repopulated to their last values, while all the other 'static' elements are.

I was thinking I could create a hidden input that would be serialized through javascript with the contents of the dynamic boxes, then read from it on $document.ready and then repopulate my boxes.

Is there a better way?

I have a page that uses jQuery to create a number of <input> DOM elements dynamically based on what user picks from a <select> box.

Let's say the user picks 4 from the select box, my script dynamically shows 4 input boxes.

The problem is when the user refreshes or goes back to this page (with the browser back button). The elements that are created dynamically are not repopulated to their last values, while all the other 'static' elements are.

I was thinking I could create a hidden input that would be serialized through javascript with the contents of the dynamic boxes, then read from it on $document.ready and then repopulate my boxes.

Is there a better way?

Share Improve this question asked Jun 3, 2009 at 19:12 andreialecuandreialecu 3,7293 gold badges30 silver badges38 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

legenden - there are a number of possible solutions to this, I would check out these history plugins for one:

  • History Remote
  • jQuery History plugin
  • Deep Linking plugin

They are a little fidgety, but you should be able to hack up something positive. I will also add, that this can probably be done by storing the dynamically elements in a cookie(s) and somehow repopulating. Check out the jQuery Cookie plugin. Hope that helped you get started.

You need to manage history yourself if you want things to work in this way. You need Really Simple History.

发布评论

评论列表(0)

  1. 暂无评论