Control of Firefox's Form Recovery
I have a page that contains multiple checkbox input elements. Toggling these alter the appearance of the page in a way that can only be done in Javascript.
My problem arises when you close and reopen the page. A brief (seemingly inconsistent) moment after the page loads, 开发者_JAVA技巧Firefox restores the state of the checkboxes without raising their onchange events.
Is there a way to determine when Firefox recovers these elements, or at the very least, is there any way to disable this functionality without requiring the users to change their browser settings?
I am also using jQuery, in case that has anything that can help.
Using autocomplete="off"
on the inputs has no effect.
If you just need to fire the change handlers, to match the page's state to the user's last preference (which seems like a good idea), then something like this should do the trick. :
$(window).load ( function () {
$('input:checked').change ();
} );
See the demo at jsBin.
"Toggling these alter the appearance of the page"
There's your problem. The page should depend on the state of the toggle, not be changed when they are toggled. I too have grappled with the "change" event and browser history. Instead of fighting it, embrace it as free storage of user specific data. Draw the page based on the input status, even if you think you know what it should be.
If you post some specific code I could suggest alterations.
精彩评论