简体   繁体   中英

anchor tag href querystring back button issue

I have several check box inputs on the page and an anchor tag.

Whenever the user checks the check boxes, I update the anchor tag href to include the query string using javascript by binding the onclick event to the check boxes.

The anchor tag navigates to a different page.

When the user clicks the browser back button, my check boxes are still checked, but the query string in the anchor tag is gone!

How do i preserve the state of the anchor tag href with the query string?

You will need to add javascript that checks the value of all checkboxes and updates the corresponding anchor tag(s). The key here is that it needs to execute on the unload event. That's going to be easiest with jQuery, something like:

jQuery(window).bind("unload", function() { // ...

The key is that most browsers cache the page, so you can't use standard onload events, as those aren't fired. This question has a lot of added detail about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM