Remember which tab was active after refresh

前端 未结 17 2177
眼角桃花
眼角桃花 2020-11-27 04:43

I\'m using jquery tabs on a web page and when the page is refreshed it loses what ever tab I had been on and goes back to the first tab.

Has anyone come across this

17条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 05:03

    My company blocks cookies so I found a workaround. Simply keep track of the tab using a hidden field and pass that value back once the request is finished. It's not pretty but it gets the job done.

    <% if(request.getAttribute("tab")==null) { %>
        $("#tabs").tabs();
    <% } else { %>
        $("#tabs").tabs({selected:<%=request.getAttribute("tab").toString() %>});
    <% } %>
    

    On the back end I just set the attribute

    request.setAttribute("tab", f.get("tab").toString());
    

    Hope this helps.

提交回复
热议问题