Browser back behavior
On websites, there are other patterns besides clicking links when loading pages, such as using the browser’s back (forward) buttons. In order to avoid misleading users, it is necessary to control every detail of the behavior.
For example, there is a function that automatically switches the order of items.
This feature was implemented with the aim of reducing bias in voting by displaying items in random order. However, on the flip side of convenience, there is a possibility that selections may be swapped when the browser’s back button is used.
By adding the following control, you can reset the browser when you go back.
window.addEventListener('pageshow', function(event) {
document.querySelectorAll('[name="data[]"]').forEach(function(element) {
element.checked = false;
});
});However, since this process is executed when the browser’s back or forward buttons are pressed, there may be a time lag in the reset process, and it can be quite troublesome when considering the processing of radio buttons.
Realistically, processing optimized for system specifications is best.
This time, we adopted a method that forces a reset for both checkboxes and radio buttons. If you do not plan to use it strictly, it is not necessary to control the behavior of the browser back button. This should also be changed in the specifications.
It is important to design in advance the operations that users are likely to perform.