I tried to understand even the bubbles, and I'm not quite sure that I am completely following it. I started reading about this to alert users when they leave a page on my website if they start entering data into the form (similar to how StackOverflow does it!).
The following code seems to work in a cross browser:
var entereddata = false;
$(document).ready(function()
{
$('#contactform').bind('keypress',function(e) {
if((e.which > 96 && e.which < 123) || (e.which > 47 && e.which < 58)) {
entereddata = true;
}
});
});
function confirmLeave(e, d)
{
if(!e) e = window.event;
if(!d) d = entereddata;
var confirmationMessage = 'It appears you have started to enter information into the contact form, but have not yet submitted it';
if(!d)
{
e.cancelBubble = true;
} else
{
return confirmationMessage;
}
}
window.onbeforeunload=confirmLeave;
However, this also gets called when I click the submit button for the form I don't want. I tried various code additions, such as adding:
if($('#submit').click()){
submitted=true;
} else {
submitted=false;
}
if (! d) if (! d && == false) ; , ( , ) , , , , - !
, - , e.cancelBubble = true; , .
, :
- , , , .
- eventBubbling; : inputData , . ? e.cancelBubble = false, inputData , e.cancelBubble = true, inputData ? e.cancelBubble ?
, e.stopPropagation
, firefox ?
, - .
,