jQuery .ready in a dynamically inserted iframe
I answered a similar question (see Javascript callback when IFRAME is finished loading?).
You can obtain control over the iframe load event with the following code:
function callIframe(url, callback) {
$(document.body).append('<IFRAME id="myId" ...>');
$('iframe#myId').attr('src', url);
$('iframe#myId').load(function() {
callback(this);
});
}
In dealing with iframes I found good enough to use load event instead of document ready event.
Dynamically Adding HTML into an iFrame - Javascript
check out this post:
addEventListener to iFrame
you need to use
$('#myIFrame').load(function(){
....
How can I use jQuery to dynamically load html into an iFrame?
You don't try to copy the form to a hidden iframe, you submit the form to the hidden iframe. Set the target
attribute (or property) of the form to the name of the iframe.
var fileForm = $('#attachFile form').prop('target', 'hiddenIframe');
$('#emptyDiv').html('<iframe name="hiddenIframe" id="hiddenIFrame"></iframe>');
or
<form action="my_file.php" method="post" enctype="multipart/form-data" id="uploadFile" target="hiddenIframe">
<input type="file" name="files" id="files">
<input id="fileUploadButton" type="submit" name="upload" value="Upload File" onclick="submitFile()">
</form>
Check if dynamically added element is ready
I put this code into iframe
$(document).ready(function() {
window.parent.postMessage('load complete', 'http://jahsdjhasjkdasdjkas.com');
});
and this into main page
window.addEventListener('message', receiveMessage, false);
function loadinghide(){
$('#loading').fadeOut();
};
function receiveMessage(evt)
{
if (evt.origin === 'ajhsdjashdjkasdas.com')
{
loadinghide();
}
}
Html of a webpage dynamically inserted into iframe looks slightly different from original page
Some default settings like margins and paddings differ between quirks and standards mode.
So make sure that The DOCTYPE declaration is the same as the original.
Or more formally, if the original page has any DOCTYPE declaration that triggers standards mode, the source in your iframe needs to have a DOCTYPE like that as well. (Doesn't have to be identical, as long as they trigger the same mode.)
Related Topics
How to Fire and Forget a Promise in Nodejs (Es7)
Multiple Assignment in JavaScript? What Does [A,B,C] = [1, 2, 3]; Mean
Differencebetween Parseint() and Number()
What Is the Purpose of a Plus Symbol Before a Variable
Event Handlers Inside a JavaScript Loop - Need a Closure
What Does "Options = Options || {}" Mean in JavaScript
What Do These JavaScript Bitwise Operators Do
Using Rails 3.1, Where Do You Put Your "Page Specific" JavaScript Code
How to Use JavaScript to Change the Meta-Tags of the Page
Declaring Multiple Variables in JavaScript
What's Wrong with Awaiting a Promise Chain
Why Is My Function Call That Should Be Scheduled by Settimeout Executed Immediately
Change Url Parameters and Specify Defaults Using JavaScript
Jquery Click/Toggle Between Two Functions
Get Global Variable Dynamically by Name String in JavaScript
How to Concatenate a String with a Variable
Why Does Firebase Lose Reference Outside the Once() Function