Reputation: 17
I changed the content of an HTML5 iframe Tag with a function, however; the function reloads the whole page, which is an issue, as I am not intending for it to do that. Reloading the page in the iframe tag is duplicating the content. This is being caused because I am using the onload event trigger with the iframe tag. Is there a way to block reload in a function with doc.write => document?
Many thanks
iframe.onload = function() {
function_insert_txt_iframe ...
}
window.addEventListener("DOMContentLoaded", function(event) {
function_insert_txt_window ...
}
Upvotes: 0
Views: 171
Reputation: 2520
Document.readyState
seems like it might do what you want:
document.addEventListener('readystatechange', event => {
if (event.target.readyState === 'interactive') {
function_insert_txt_iframe();
}
else if (event.target.readyState === 'complete') {
function_insert_txt_window();
}
});
See here: https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
Upvotes: 0
Reputation: 24294
You can use a variable called isLoaded
and instantiate it with value false. If the value is true you don't need to reload the page:
var isLoaded = true;
iframe.onload = function() {
if(!isLoaded) function_insert_txt_iframe ...
}
window.addEventListener("DOMContentLoaded", function(event) {
if(!isLoaded) function_insert_txt_window ...
}
Upvotes: 1