我正在尝试在iframe中的onload事件上加载Ajax页面(如果可能的话?)。
所以我有一个iframe:
和Javascript
function loadIjax(divId,strURL)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// show ajax response
parent.document.getElementById(divID).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",strURL,true);
xmlhttp.send();
}
因此,想法是在加载页面时在iframe中加载page.php。
我的问题,到目前为止,这甚至可能是什么?它在这一点上不起作用。问题是Javascript在iframe中找不到div。如果我将相同的div放在iframe之外,它确实有用。