Rerun jQuery function if focus is still on input when iframe reloads?












0















I have an input field which when focused fires a jQuery function to hide some content in the iframe, this works fine. But if the iframe content is reloaded/refreshed while the input field is still in focus the jQuery function will not fire again. Is it possible to rerun the jQuery below if the input is still in focus after iframe content is reloaded?



$('#_customize-input-checkin\[message\]').focus(function() {
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
});









share|improve this question























  • Suggest putting code in iframe page that calls a parent window function either directly or with postMessage API

    – charlietfl
    Nov 25 '18 at 20:25


















0















I have an input field which when focused fires a jQuery function to hide some content in the iframe, this works fine. But if the iframe content is reloaded/refreshed while the input field is still in focus the jQuery function will not fire again. Is it possible to rerun the jQuery below if the input is still in focus after iframe content is reloaded?



$('#_customize-input-checkin\[message\]').focus(function() {
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
});









share|improve this question























  • Suggest putting code in iframe page that calls a parent window function either directly or with postMessage API

    – charlietfl
    Nov 25 '18 at 20:25
















0












0








0








I have an input field which when focused fires a jQuery function to hide some content in the iframe, this works fine. But if the iframe content is reloaded/refreshed while the input field is still in focus the jQuery function will not fire again. Is it possible to rerun the jQuery below if the input is still in focus after iframe content is reloaded?



$('#_customize-input-checkin\[message\]').focus(function() {
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
});









share|improve this question














I have an input field which when focused fires a jQuery function to hide some content in the iframe, this works fine. But if the iframe content is reloaded/refreshed while the input field is still in focus the jQuery function will not fire again. Is it possible to rerun the jQuery below if the input is still in focus after iframe content is reloaded?



$('#_customize-input-checkin\[message\]').focus(function() {
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
});






javascript jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 20:13









joq3joq3

156




156













  • Suggest putting code in iframe page that calls a parent window function either directly or with postMessage API

    – charlietfl
    Nov 25 '18 at 20:25





















  • Suggest putting code in iframe page that calls a parent window function either directly or with postMessage API

    – charlietfl
    Nov 25 '18 at 20:25



















Suggest putting code in iframe page that calls a parent window function either directly or with postMessage API

– charlietfl
Nov 25 '18 at 20:25







Suggest putting code in iframe page that calls a parent window function either directly or with postMessage API

– charlietfl
Nov 25 '18 at 20:25














1 Answer
1






active

oldest

votes


















-1














You can handle iframe onload event to execute the same logic. Try the following-



function exec(){
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
}

$('#_customize-input-checkin\[message\]').focus(function() {
exec();
});

$("#customize-preview iframe").load(function(){
if($('#_customize-input-checkin\[message\]').is(":focus"))
exec();
});





share|improve this answer


























  • That's not how to add event listener to jQuery object. Will only register initial load using this approach also

    – charlietfl
    Nov 25 '18 at 20:21













  • @charlietfl thanks, updated

    – kamalpreet
    Nov 25 '18 at 20:23











  • @charlietfl what is the correct way to do it?

    – joq3
    Nov 25 '18 at 20:32











  • @charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

    – kamalpreet
    Nov 25 '18 at 20:33











  • @joq3, did you try above approach?

    – kamalpreet
    Nov 25 '18 at 20:34











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%2f53471483%2frerun-jquery-function-if-focus-is-still-on-input-when-iframe-reloads%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














You can handle iframe onload event to execute the same logic. Try the following-



function exec(){
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
}

$('#_customize-input-checkin\[message\]').focus(function() {
exec();
});

$("#customize-preview iframe").load(function(){
if($('#_customize-input-checkin\[message\]').is(":focus"))
exec();
});





share|improve this answer


























  • That's not how to add event listener to jQuery object. Will only register initial load using this approach also

    – charlietfl
    Nov 25 '18 at 20:21













  • @charlietfl thanks, updated

    – kamalpreet
    Nov 25 '18 at 20:23











  • @charlietfl what is the correct way to do it?

    – joq3
    Nov 25 '18 at 20:32











  • @charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

    – kamalpreet
    Nov 25 '18 at 20:33











  • @joq3, did you try above approach?

    – kamalpreet
    Nov 25 '18 at 20:34
















-1














You can handle iframe onload event to execute the same logic. Try the following-



function exec(){
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
}

$('#_customize-input-checkin\[message\]').focus(function() {
exec();
});

$("#customize-preview iframe").load(function(){
if($('#_customize-input-checkin\[message\]').is(":focus"))
exec();
});





share|improve this answer


























  • That's not how to add event listener to jQuery object. Will only register initial load using this approach also

    – charlietfl
    Nov 25 '18 at 20:21













  • @charlietfl thanks, updated

    – kamalpreet
    Nov 25 '18 at 20:23











  • @charlietfl what is the correct way to do it?

    – joq3
    Nov 25 '18 at 20:32











  • @charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

    – kamalpreet
    Nov 25 '18 at 20:33











  • @joq3, did you try above approach?

    – kamalpreet
    Nov 25 '18 at 20:34














-1












-1








-1







You can handle iframe onload event to execute the same logic. Try the following-



function exec(){
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
}

$('#_customize-input-checkin\[message\]').focus(function() {
exec();
});

$("#customize-preview iframe").load(function(){
if($('#_customize-input-checkin\[message\]').is(":focus"))
exec();
});





share|improve this answer















You can handle iframe onload event to execute the same logic. Try the following-



function exec(){
var $iframe = $("#customize-preview iframe").contents();
$("#alert_check_in_notification_sent", $iframe).css("display", "block");
$("#check-in-wrap", $iframe).css("display", "none");
}

$('#_customize-input-checkin\[message\]').focus(function() {
exec();
});

$("#customize-preview iframe").load(function(){
if($('#_customize-input-checkin\[message\]').is(":focus"))
exec();
});






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 20:21

























answered Nov 25 '18 at 20:19









kamalpreetkamalpreet

1,1851435




1,1851435













  • That's not how to add event listener to jQuery object. Will only register initial load using this approach also

    – charlietfl
    Nov 25 '18 at 20:21













  • @charlietfl thanks, updated

    – kamalpreet
    Nov 25 '18 at 20:23











  • @charlietfl what is the correct way to do it?

    – joq3
    Nov 25 '18 at 20:32











  • @charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

    – kamalpreet
    Nov 25 '18 at 20:33











  • @joq3, did you try above approach?

    – kamalpreet
    Nov 25 '18 at 20:34



















  • That's not how to add event listener to jQuery object. Will only register initial load using this approach also

    – charlietfl
    Nov 25 '18 at 20:21













  • @charlietfl thanks, updated

    – kamalpreet
    Nov 25 '18 at 20:23











  • @charlietfl what is the correct way to do it?

    – joq3
    Nov 25 '18 at 20:32











  • @charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

    – kamalpreet
    Nov 25 '18 at 20:33











  • @joq3, did you try above approach?

    – kamalpreet
    Nov 25 '18 at 20:34

















That's not how to add event listener to jQuery object. Will only register initial load using this approach also

– charlietfl
Nov 25 '18 at 20:21







That's not how to add event listener to jQuery object. Will only register initial load using this approach also

– charlietfl
Nov 25 '18 at 20:21















@charlietfl thanks, updated

– kamalpreet
Nov 25 '18 at 20:23





@charlietfl thanks, updated

– kamalpreet
Nov 25 '18 at 20:23













@charlietfl what is the correct way to do it?

– joq3
Nov 25 '18 at 20:32





@charlietfl what is the correct way to do it?

– joq3
Nov 25 '18 at 20:32













@charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

– kamalpreet
Nov 25 '18 at 20:33





@charlietfl this small example shows how load event executes everytime iframe loads - jsfiddle.net/npyz2ga6

– kamalpreet
Nov 25 '18 at 20:33













@joq3, did you try above approach?

– kamalpreet
Nov 25 '18 at 20:34





@joq3, did you try above approach?

– kamalpreet
Nov 25 '18 at 20:34




















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%2f53471483%2frerun-jquery-function-if-focus-is-still-on-input-when-iframe-reloads%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

To store a contact into the json file from server.js file using a class in NodeJS

Marschland

Redirect URL with Chrome Remote Debugging Android Devices