Remember which tab was active after refresh

前端 未结 17 2242
眼角桃花
眼角桃花 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:24

    When web pages refresh, they reload their state from the server, by requesting the page again.

    Either the webserver needs to remember the state and supply the file differently than the default, or you may be able to use cookies or the hash-component of the URL and some jQuery to store the state, read it on load and restore it.

    See the jquery.cookie plugin or SWFaddress, learn about manipulating hash values yourself or the jQuery History plugin.

    The hash method has a particular attraction as it replicates changes of URL, so copy/paste of the URL still works, as do bookmarks.

提交回复
热议问题