多个选项卡的会话问题
我的页面上有一个搜索,其中有一个过滤器菜单、一个排序选项和一个页面浏览器。客户希望,如果他搜索某些内容并单击产品,然后再次单击“后退”或“搜索”,则会再次显示相同的搜索和结果。
我不想通过每个链接(错误的网址)传递所有搜索参数,因此我将所有这些数据存储在会话中。这工作正常,但有一个问题:
用户打开搜索并按“size=big”进行过滤,然后打开一个新选项卡并将过滤器更改为“size=small”。现在他的会话中有“size=small”。因此,如果他切换回第一个选项卡并单击那里的“page 2”,那么他会看到第二页,但不是像他预期的那样显示“size=big”,而是显示“size=small”。
有没有一种好的方法可以解决这个问题,而不需要一直传递所有变量(很多!)?
I have a search on my page where you have a filter Menu, a option for sorting, and a Pagebrowser. The Customer wanted, that if he searches something and clicks on a product and then clicks "back" or on "search" again, that the same search and results are shown again.
I dont want to pass all the Search Params with each link (bad urls), so I store all this data in the session. This works fine but there is one Problem:
A users opens the search and filters by "size=big" then opens a new tab and changes the filter to "size=small". There is now "size=small" in his session. So if he switches back on his first tab and clicks "page 2" there, then he sees the second page, but not for "size=big" as he expected, but for "size=small".
Is there a nice way to fix this without passing all the variables (many!) around all the time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈建议将搜索放入您的链接中。它可能会使您的链接变得不那么“漂亮”,但当我无法通过简单地发送链接将搜索结果发送给朋友时,我讨厌它。
但要回答您的问题:在每个表单中添加一个
search_id
,并将其附加到网址中。然后在会话中保存该特定search_id
的搜索。当用户刷新页面时,您可以检查是否传输 POST 搜索变量,或者会话中是否存储了该特定search_id
的变量。I would strongly suggest putting the search in your link. It might make your links less »beautiful«, but I hate it when I can't send a search result to a friend by simply sending the link.
But to answer your question: Put a
search_id
in every form, that gets appended to the url. Then save the search in the session for that specificsearch_id
. When the user refreshes the page, you can check if POST search variables are transmitted, or if there is one stored in the session for that specificsearch_id
.不,现在,浏览器在所有选项卡上实施 cookie,因此您不能在不同选项卡上拥有不同的 cookie 或会话。因此,存储状态的唯一方法是在 url 上。
No. right now, browsers implement cookies across all tabs, so you cannot have different cookies or sessions on different tabs. Thus, the only way to store state is on the url.