This question continues on from this question:
Read url and output new javascript src
My latest code is:
$(document).ready(function () {
var oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.src = 'converter.js';
// most browsers
oScript.onload = function () {
$('#converter #form').load(renderConverter());
}
// IE
oScript.onreadystatechange = function () {
if (this.readyState == 'complete') {
$('#converter #form').load(renderConverter());
}
}
document.body.appendChild(oScript);
});
The issue is on .load(renderConverter());. What this does is, it removes the entire DOM and prints what renderConverter(); asks it to print.
The function renderConverter(); uses the following to print the html:
window.document.write(html);
I changed to:
document.write(html) but it does the same thing.
How can I force it to only print within the div I have run the call back on?. The div being #converter #form.
You cannot use
document.writeafter the page has finished loading.You should use jQuery DOM manipulation instead.