Hi I have a long form that is split into a wizard. To prevent the user from hitting browser back button and losing data I have the following:
window.onbeforeunload = function() { return "Hitting back will cause you to lose all form data."; };
How would I insert a flag and apply to th开发者_运维知识库e last step so the form can be submitted properly? Thanks,
You can set a variable on the last step to true and check against it, like this:
var okToSubmit = false;
window.onbeforeunload = function() {
if(!okToSubmit) return "Hitting back will cause you to lose all form data.";
};
//set okToSubmit = true; on the last step
Without your current code I can't say exactly where to insert this, but wherever your script moves to the last step, add a okToSubmit = true;
in there.
精彩评论