How to distinguish a JS-submit from using the back button (onbeforeunload)?
I am going crazy with the onbeforeunload and form.submit(). You are my last hope for a brilliant idea...
What I have is a form. If the user clicks the back button, this causes a lot of trouble, so window.onbeforeunload shows a warning. Of couse submitting the form shall be allowed, therefore form.onsubmit sets a global variable to tell the onbeforeunload-function to shut up. So far allright.
Sometimes the form must be submitted automatically via JS. And I do not have access to the functions that call the form.submit() - or more exactly - users will create some simple code that may include a form.submit().
The point is that form.submit() does, by specification, not trigger the form's onsubmit event. Therefore trying to send a form via form.submit() regularly tells me to consider closing 开发者_高级运维the page.
So back to my hope: Does anyone have a brilliant idea how to solve this vicious circle?
Thanks a lot BurninLeo
var form = document.getElementById('the-form'),
sub = form.submit;
form.submit = function(){
alert('caught submit');
sub.apply(form);
}
form.submit();
精彩评论