Rerun jQuery function if focus is still on input when iframe reloads?
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
add a comment |
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
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
add a comment |
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
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
javascript jquery
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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();
});
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
|
show 3 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
});
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
|
show 3 more comments
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();
});
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
|
show 3 more comments
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();
});
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();
});
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
|
show 3 more comments
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
|
show 3 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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