/** * loads a page into a div * @param {string} the url you want to load * @param {string} the id of the div you wanto to populate */ function loadPage(url, divId) { if (window.XMLHttpRequest) { // Non-IE browsers req = new XMLHttpRequest(); req.onreadystatechange = function() { targetDiv(divId) }; try { req.open("GET", url, true); } catch (e) { alert(e); } req.send(null); } else if (window.ActiveXObject) { // IE req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = function() { targetDiv(divId) }; req.open("GET", url, true); req.send(); } } } /** * waits until the request is complete and makes sure and ok response was sent back * then populates the div with the html from the requested url * @param {divId} the id of the div you wanto to populate */ function targetDiv(divId) { if (req.readyState == 4) { // Complete if (req.status == 200) { // OK response document.getElementById(divId).innerHTML = req.responseText; var scriptTags = document.getElementById(divId).getElementsByTagName('script'); for(i=0; i < scriptTags.length; i++){ eval(scriptTags[i].innerHTML); } if(document.getElementById('image_ad') && document.getElementById('adunit_container')){ document.getElementById('image_ad').innerHTML = document.getElementById('adunit_container').innerHTML; } return false; } else { alert("Error: " + req.statusText); } } }