How can i modify F5 event inside of a iframe?












0














I want to know how can i get the F5 to use it inside of an iframe, because i did it but outside of it, in my page. I rewrite the URL of my page with this:



 window.history.replaceState({}, '', 'OFRAME');


and when i tried to refresh it i got an error, but i fixed it, with this:



var URLactual = '';
$(document).ready(function () {
if (URLactual == '') {

URLactual = window.parent.location.href;
}
window.history.replaceState({}, '', 'OFRAME');
$(document.body).on("keydown", this, function (event) {
if (event.keyCode == 116) {
window.location.assign(URLactual);
}
});


});



So it works but only in my first page, when navigate inside of the page that contains my iframe and i press F5, i don't know why or how but it doesn't read the script.



After that i press again F5 and the script works normally but doesn't do what need to do.










share|improve this question
























  • Iframes have their own windows and when focused the events occur in that window with no knowledge of or bubbling to parent window listeners. If iframe is from a different origin than main page (protocol, domain, subdomain or port) you can't access it's window using script from parent unless you control the code in both
    – charlietfl
    Nov 22 at 20:45












  • So... is iframe from same origin as page?
    – charlietfl
    Nov 22 at 20:49










  • as the page that shows?
    – ASpong
    Nov 22 at 20:53










  • Yes...as in main page from example.com and iframe page from example.com
    – charlietfl
    Nov 22 at 20:54












  • No it's not :/ So what can i do? could i refresh in other way my iframe? I have access to those pages that my iframe shows
    – ASpong
    Nov 22 at 20:58


















0














I want to know how can i get the F5 to use it inside of an iframe, because i did it but outside of it, in my page. I rewrite the URL of my page with this:



 window.history.replaceState({}, '', 'OFRAME');


and when i tried to refresh it i got an error, but i fixed it, with this:



var URLactual = '';
$(document).ready(function () {
if (URLactual == '') {

URLactual = window.parent.location.href;
}
window.history.replaceState({}, '', 'OFRAME');
$(document.body).on("keydown", this, function (event) {
if (event.keyCode == 116) {
window.location.assign(URLactual);
}
});


});



So it works but only in my first page, when navigate inside of the page that contains my iframe and i press F5, i don't know why or how but it doesn't read the script.



After that i press again F5 and the script works normally but doesn't do what need to do.










share|improve this question
























  • Iframes have their own windows and when focused the events occur in that window with no knowledge of or bubbling to parent window listeners. If iframe is from a different origin than main page (protocol, domain, subdomain or port) you can't access it's window using script from parent unless you control the code in both
    – charlietfl
    Nov 22 at 20:45












  • So... is iframe from same origin as page?
    – charlietfl
    Nov 22 at 20:49










  • as the page that shows?
    – ASpong
    Nov 22 at 20:53










  • Yes...as in main page from example.com and iframe page from example.com
    – charlietfl
    Nov 22 at 20:54












  • No it's not :/ So what can i do? could i refresh in other way my iframe? I have access to those pages that my iframe shows
    – ASpong
    Nov 22 at 20:58
















0












0








0







I want to know how can i get the F5 to use it inside of an iframe, because i did it but outside of it, in my page. I rewrite the URL of my page with this:



 window.history.replaceState({}, '', 'OFRAME');


and when i tried to refresh it i got an error, but i fixed it, with this:



var URLactual = '';
$(document).ready(function () {
if (URLactual == '') {

URLactual = window.parent.location.href;
}
window.history.replaceState({}, '', 'OFRAME');
$(document.body).on("keydown", this, function (event) {
if (event.keyCode == 116) {
window.location.assign(URLactual);
}
});


});



So it works but only in my first page, when navigate inside of the page that contains my iframe and i press F5, i don't know why or how but it doesn't read the script.



After that i press again F5 and the script works normally but doesn't do what need to do.










share|improve this question















I want to know how can i get the F5 to use it inside of an iframe, because i did it but outside of it, in my page. I rewrite the URL of my page with this:



 window.history.replaceState({}, '', 'OFRAME');


and when i tried to refresh it i got an error, but i fixed it, with this:



var URLactual = '';
$(document).ready(function () {
if (URLactual == '') {

URLactual = window.parent.location.href;
}
window.history.replaceState({}, '', 'OFRAME');
$(document.body).on("keydown", this, function (event) {
if (event.keyCode == 116) {
window.location.assign(URLactual);
}
});


});



So it works but only in my first page, when navigate inside of the page that contains my iframe and i press F5, i don't know why or how but it doesn't read the script.



After that i press again F5 and the script works normally but doesn't do what need to do.







javascript iframe refresh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 20:50

























asked Nov 22 at 20:39









ASpong

12




12












  • Iframes have their own windows and when focused the events occur in that window with no knowledge of or bubbling to parent window listeners. If iframe is from a different origin than main page (protocol, domain, subdomain or port) you can't access it's window using script from parent unless you control the code in both
    – charlietfl
    Nov 22 at 20:45












  • So... is iframe from same origin as page?
    – charlietfl
    Nov 22 at 20:49










  • as the page that shows?
    – ASpong
    Nov 22 at 20:53










  • Yes...as in main page from example.com and iframe page from example.com
    – charlietfl
    Nov 22 at 20:54












  • No it's not :/ So what can i do? could i refresh in other way my iframe? I have access to those pages that my iframe shows
    – ASpong
    Nov 22 at 20:58




















  • Iframes have their own windows and when focused the events occur in that window with no knowledge of or bubbling to parent window listeners. If iframe is from a different origin than main page (protocol, domain, subdomain or port) you can't access it's window using script from parent unless you control the code in both
    – charlietfl
    Nov 22 at 20:45












  • So... is iframe from same origin as page?
    – charlietfl
    Nov 22 at 20:49










  • as the page that shows?
    – ASpong
    Nov 22 at 20:53










  • Yes...as in main page from example.com and iframe page from example.com
    – charlietfl
    Nov 22 at 20:54












  • No it's not :/ So what can i do? could i refresh in other way my iframe? I have access to those pages that my iframe shows
    – ASpong
    Nov 22 at 20:58


















Iframes have their own windows and when focused the events occur in that window with no knowledge of or bubbling to parent window listeners. If iframe is from a different origin than main page (protocol, domain, subdomain or port) you can't access it's window using script from parent unless you control the code in both
– charlietfl
Nov 22 at 20:45






Iframes have their own windows and when focused the events occur in that window with no knowledge of or bubbling to parent window listeners. If iframe is from a different origin than main page (protocol, domain, subdomain or port) you can't access it's window using script from parent unless you control the code in both
– charlietfl
Nov 22 at 20:45














So... is iframe from same origin as page?
– charlietfl
Nov 22 at 20:49




So... is iframe from same origin as page?
– charlietfl
Nov 22 at 20:49












as the page that shows?
– ASpong
Nov 22 at 20:53




as the page that shows?
– ASpong
Nov 22 at 20:53












Yes...as in main page from example.com and iframe page from example.com
– charlietfl
Nov 22 at 20:54






Yes...as in main page from example.com and iframe page from example.com
– charlietfl
Nov 22 at 20:54














No it's not :/ So what can i do? could i refresh in other way my iframe? I have access to those pages that my iframe shows
– ASpong
Nov 22 at 20:58






No it's not :/ So what can i do? could i refresh in other way my iframe? I have access to those pages that my iframe shows
– ASpong
Nov 22 at 20:58



















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%2f53437750%2fhow-can-i-modify-f5-event-inside-of-a-iframe%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53437750%2fhow-can-i-modify-f5-event-inside-of-a-iframe%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

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks