UPDATE:
I was mislead, by some mistake I had made, into thinking that I could not both have a running script updating the screen AND an outstanding submit that would reload the page upon completion.
You can do this, and I have. The way that I did it was to place my updater on a startTimeout and let the submit continue.
$('#JQF').on('submit', function(){
start();
return true;
});
...
start:
function (xhr, s) {
$(".appMainMsg").hide();
bar = document.getElementById("ProgressBar");
if (bar)
{
eta = document.getElementById("ProgressBarEta");
startTime = new Date();
infoUpdated = 0;
infoRequested = 0;
$(bar).empty().progressbar();
setTimeout(requestInfo, 2);
}
},
...
ORIGINAL Question:
I have a page that posts a form with file uploads and targets the response to an hidden iframe. When the iframe finishes loading, it calls a function in the (main) page. If all looks good, I want to move the contents of the body that loaded into the iframe to the main page’s body, else I will just leave things alone. I do have jquery loaded so I’d like to use that.
<body>
<iframe name='ifr' id='ifr' style='display: none;'></iframe>
<form target='ifr' method='post' action='mypage.php'>
</form>
<script>
function finished()
{ if (iLikeIt)
{
//replace body contents with ifr.body.contents
// keeping all event handlers attached
// something like...
WHAT DO I PUT HERE?
}
}
</script>
</body>
The page loaded into the iframe, ends with:
<script>
setTimeout(parent.finished, 1000); // some time for navel gazing
</script>
You do not need iframe to do this. I recommend to submit your form by ajax.
Since you have jquery loaded, the easiest option for you is to use jquery-form plugin.
Here is a working example of what you are looking for:
index.html:
upload.php: