To make an Ajax JavaScript, MooTools is used for DOM navigation. One iframe is called "buffer", one div is called "display". JavaScript copies iframe content into a div.
onLoad on iframe triggers handler(), a counter makes sure it only runs once because otherwise Firefox will go into a feedback loop. What I think happens: iframe onLoad > handler() > copyBuffer() > change src of iframe and Firefox takes that as an onLoad again.copybuffer() is called, sets src of iframe, copies iframe content into div, then erases iframe content.count=0;
function handler(){
if (count==0){
copyBuffer();
count++;
}
}
function copyBuffer(){
$('buffer').set('src','http://www.somelink.com/');
if (window.frames['buffer'] && $('display') ) {
$('display').innerHTML = window.frames['buffer'].document.body.innerHTML;
window.frames['buffer'].document.body.innerHTML="";
}
}
The content is not loaded into the div. But if I either remove the counter and let the script run in a feedback loop the content is copied into the div (but it keeps loading in the status bar) or insert an alert in the copyBuffer() function (the content is copied without the feedback loop). Why does this happen?
The If wrapped around the copying code, what does it do? If I remove it, the code does not work in Safari and Chrome.
The iframe has not loaded the page when you try to access it, so it cannot get the contents..
I believe the following would work, by adding a load handler on the iframe and do the copy inside that..
function handler(){
$('buffer').load( function(){copyBuffer();} ).attr('src','http://www.somelink.com/');
}
function copyBuffer(){
if (window.frames['buffer'] && $('display') )
{
$('display').innerHTML = window.frames['buffer'].document.body.innerHTML;
window.frames['buffer'].document.body.innerHTML="";
}
}