confirm executed multiple times, console.log only once in on('click') event












0















I tried making a jquery function that works together with a bpopup (iframe) function. I want to show a confirmation message before trying to close the iframe. I added a confirm message that shows after a change but after i submit the form the confirm box gets duplicated. I tried debugging and checked how many times the function got executed so i did a console.log but this console.log only executed once when the confirm message got executed multiple times. this is the function:



function confirm_changed(){
var changed = false;
$('.b-modal', parent.document).on('click', function(){
if(changed && confirm('Weet je zeker dat je dit scherm wilt verlaten?')){
$('.b-modal', parent.document).removeClass('changed');
}
});
$(document).one('input', function(){
$('.b-modal', parent.document).addClass('changed');
changed = true;
});
}


This function gets called in the document.ready and this is the bpopup prototype function where i added the condition for the confirm message:



function r(){
setTimeout(function(){
if(c('.changed').length === 0){
a.modal && c(".b-modal." + b.data("id")).fadeTo(a.speed, 0, function(){
c(this).remove()
});
a.scrollBar || c("html").css("overflow", "auto");
c(".b-modal." + e).unbind("click");
f.unbind("keydown." + e);
k.unbind("." + e).data("bPopup", 0 < k.data("bPopup") - 1 ? k.data("bPopup") - 1 : null);
b.undelegate(".bClose, ." + a.closeClass, "click." + e, r).data("bPopup", null);
clearTimeout(H);
G();
return !1
}
}, 0);
}


This function closes the iframe.



I added the timeout so that this function gets executed after the confirm message. after the form gets submitted and everything went through the validations the class gets deleted.










share|improve this question

























  • you may try with off() like $('.b-modal', parent.document).off().on('click', function(){

    – Shree
    Nov 20 '18 at 9:05











  • That didn't fix the problem, this function also seems to give problems with the input fields. Sometimes i can't focus the fields and after a while of waiting i can use them again. There doesn't seem to be any logic moment when this happens.

    – Martin ter Wee
    Nov 20 '18 at 9:52











  • The console gives an error message: 'Uncaught TypeError: Cannot read property 'document' of null'. I get the feeling that somehow the parent.document gets duplicated but i'm not sure how to fix it.

    – Martin ter Wee
    Nov 20 '18 at 9:55











  • I figured it out, i put a function in the prototype that checks for the confirmation instead of in a different js script.

    – Martin ter Wee
    Nov 20 '18 at 11:19
















0















I tried making a jquery function that works together with a bpopup (iframe) function. I want to show a confirmation message before trying to close the iframe. I added a confirm message that shows after a change but after i submit the form the confirm box gets duplicated. I tried debugging and checked how many times the function got executed so i did a console.log but this console.log only executed once when the confirm message got executed multiple times. this is the function:



function confirm_changed(){
var changed = false;
$('.b-modal', parent.document).on('click', function(){
if(changed && confirm('Weet je zeker dat je dit scherm wilt verlaten?')){
$('.b-modal', parent.document).removeClass('changed');
}
});
$(document).one('input', function(){
$('.b-modal', parent.document).addClass('changed');
changed = true;
});
}


This function gets called in the document.ready and this is the bpopup prototype function where i added the condition for the confirm message:



function r(){
setTimeout(function(){
if(c('.changed').length === 0){
a.modal && c(".b-modal." + b.data("id")).fadeTo(a.speed, 0, function(){
c(this).remove()
});
a.scrollBar || c("html").css("overflow", "auto");
c(".b-modal." + e).unbind("click");
f.unbind("keydown." + e);
k.unbind("." + e).data("bPopup", 0 < k.data("bPopup") - 1 ? k.data("bPopup") - 1 : null);
b.undelegate(".bClose, ." + a.closeClass, "click." + e, r).data("bPopup", null);
clearTimeout(H);
G();
return !1
}
}, 0);
}


This function closes the iframe.



I added the timeout so that this function gets executed after the confirm message. after the form gets submitted and everything went through the validations the class gets deleted.










share|improve this question

























  • you may try with off() like $('.b-modal', parent.document).off().on('click', function(){

    – Shree
    Nov 20 '18 at 9:05











  • That didn't fix the problem, this function also seems to give problems with the input fields. Sometimes i can't focus the fields and after a while of waiting i can use them again. There doesn't seem to be any logic moment when this happens.

    – Martin ter Wee
    Nov 20 '18 at 9:52











  • The console gives an error message: 'Uncaught TypeError: Cannot read property 'document' of null'. I get the feeling that somehow the parent.document gets duplicated but i'm not sure how to fix it.

    – Martin ter Wee
    Nov 20 '18 at 9:55











  • I figured it out, i put a function in the prototype that checks for the confirmation instead of in a different js script.

    – Martin ter Wee
    Nov 20 '18 at 11:19














0












0








0








I tried making a jquery function that works together with a bpopup (iframe) function. I want to show a confirmation message before trying to close the iframe. I added a confirm message that shows after a change but after i submit the form the confirm box gets duplicated. I tried debugging and checked how many times the function got executed so i did a console.log but this console.log only executed once when the confirm message got executed multiple times. this is the function:



function confirm_changed(){
var changed = false;
$('.b-modal', parent.document).on('click', function(){
if(changed && confirm('Weet je zeker dat je dit scherm wilt verlaten?')){
$('.b-modal', parent.document).removeClass('changed');
}
});
$(document).one('input', function(){
$('.b-modal', parent.document).addClass('changed');
changed = true;
});
}


This function gets called in the document.ready and this is the bpopup prototype function where i added the condition for the confirm message:



function r(){
setTimeout(function(){
if(c('.changed').length === 0){
a.modal && c(".b-modal." + b.data("id")).fadeTo(a.speed, 0, function(){
c(this).remove()
});
a.scrollBar || c("html").css("overflow", "auto");
c(".b-modal." + e).unbind("click");
f.unbind("keydown." + e);
k.unbind("." + e).data("bPopup", 0 < k.data("bPopup") - 1 ? k.data("bPopup") - 1 : null);
b.undelegate(".bClose, ." + a.closeClass, "click." + e, r).data("bPopup", null);
clearTimeout(H);
G();
return !1
}
}, 0);
}


This function closes the iframe.



I added the timeout so that this function gets executed after the confirm message. after the form gets submitted and everything went through the validations the class gets deleted.










share|improve this question
















I tried making a jquery function that works together with a bpopup (iframe) function. I want to show a confirmation message before trying to close the iframe. I added a confirm message that shows after a change but after i submit the form the confirm box gets duplicated. I tried debugging and checked how many times the function got executed so i did a console.log but this console.log only executed once when the confirm message got executed multiple times. this is the function:



function confirm_changed(){
var changed = false;
$('.b-modal', parent.document).on('click', function(){
if(changed && confirm('Weet je zeker dat je dit scherm wilt verlaten?')){
$('.b-modal', parent.document).removeClass('changed');
}
});
$(document).one('input', function(){
$('.b-modal', parent.document).addClass('changed');
changed = true;
});
}


This function gets called in the document.ready and this is the bpopup prototype function where i added the condition for the confirm message:



function r(){
setTimeout(function(){
if(c('.changed').length === 0){
a.modal && c(".b-modal." + b.data("id")).fadeTo(a.speed, 0, function(){
c(this).remove()
});
a.scrollBar || c("html").css("overflow", "auto");
c(".b-modal." + e).unbind("click");
f.unbind("keydown." + e);
k.unbind("." + e).data("bPopup", 0 < k.data("bPopup") - 1 ? k.data("bPopup") - 1 : null);
b.undelegate(".bClose, ." + a.closeClass, "click." + e, r).data("bPopup", null);
clearTimeout(H);
G();
return !1
}
}, 0);
}


This function closes the iframe.



I added the timeout so that this function gets executed after the confirm message. after the form gets submitted and everything went through the validations the class gets deleted.







javascript jquery iframe confirm bpopup






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 9:49









executable

1,7972822




1,7972822










asked Nov 20 '18 at 8:44









Martin ter WeeMartin ter Wee

87




87













  • you may try with off() like $('.b-modal', parent.document).off().on('click', function(){

    – Shree
    Nov 20 '18 at 9:05











  • That didn't fix the problem, this function also seems to give problems with the input fields. Sometimes i can't focus the fields and after a while of waiting i can use them again. There doesn't seem to be any logic moment when this happens.

    – Martin ter Wee
    Nov 20 '18 at 9:52











  • The console gives an error message: 'Uncaught TypeError: Cannot read property 'document' of null'. I get the feeling that somehow the parent.document gets duplicated but i'm not sure how to fix it.

    – Martin ter Wee
    Nov 20 '18 at 9:55











  • I figured it out, i put a function in the prototype that checks for the confirmation instead of in a different js script.

    – Martin ter Wee
    Nov 20 '18 at 11:19



















  • you may try with off() like $('.b-modal', parent.document).off().on('click', function(){

    – Shree
    Nov 20 '18 at 9:05











  • That didn't fix the problem, this function also seems to give problems with the input fields. Sometimes i can't focus the fields and after a while of waiting i can use them again. There doesn't seem to be any logic moment when this happens.

    – Martin ter Wee
    Nov 20 '18 at 9:52











  • The console gives an error message: 'Uncaught TypeError: Cannot read property 'document' of null'. I get the feeling that somehow the parent.document gets duplicated but i'm not sure how to fix it.

    – Martin ter Wee
    Nov 20 '18 at 9:55











  • I figured it out, i put a function in the prototype that checks for the confirmation instead of in a different js script.

    – Martin ter Wee
    Nov 20 '18 at 11:19

















you may try with off() like $('.b-modal', parent.document).off().on('click', function(){

– Shree
Nov 20 '18 at 9:05





you may try with off() like $('.b-modal', parent.document).off().on('click', function(){

– Shree
Nov 20 '18 at 9:05













That didn't fix the problem, this function also seems to give problems with the input fields. Sometimes i can't focus the fields and after a while of waiting i can use them again. There doesn't seem to be any logic moment when this happens.

– Martin ter Wee
Nov 20 '18 at 9:52





That didn't fix the problem, this function also seems to give problems with the input fields. Sometimes i can't focus the fields and after a while of waiting i can use them again. There doesn't seem to be any logic moment when this happens.

– Martin ter Wee
Nov 20 '18 at 9:52













The console gives an error message: 'Uncaught TypeError: Cannot read property 'document' of null'. I get the feeling that somehow the parent.document gets duplicated but i'm not sure how to fix it.

– Martin ter Wee
Nov 20 '18 at 9:55





The console gives an error message: 'Uncaught TypeError: Cannot read property 'document' of null'. I get the feeling that somehow the parent.document gets duplicated but i'm not sure how to fix it.

– Martin ter Wee
Nov 20 '18 at 9:55













I figured it out, i put a function in the prototype that checks for the confirmation instead of in a different js script.

– Martin ter Wee
Nov 20 '18 at 11:19





I figured it out, i put a function in the prototype that checks for the confirmation instead of in a different js script.

– Martin ter Wee
Nov 20 '18 at 11:19












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389171%2fconfirm-executed-multiple-times-console-log-only-once-in-onclick-event%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389171%2fconfirm-executed-multiple-times-console-log-only-once-in-onclick-event%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents