【问题标题】:problem accessing an iframe that was called using ajax访问使用 ajax 调用的 iframe 时出现问题
【发布时间】:2010-10-10 14:58:35
【问题描述】:

我在当前页面上调用了一个使用 ajax 的 iframe,并尝试打印该页面,但正在打印空白页,有人可以帮我解决这个问题

我所做的是:当前页面:

<input type="button" onclick=verifyControl('1001') >
<div id='pa_print'></div>

js文件函数:

function verifyControl(rNo) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="js/p_Print.php";
    url=url+"?control_no="+rNo;
    xmlHttp.onreadystatechange=paymentPrintVerify;
    xmlHttp.open("GET",url,true);
    xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlHttp.send(null);
    remitCont_no=document.getElementById("remitContNo").value;
    if(rNo!=remitCont_no) {
        alert("invalid remit control no");
        return;
    }   
}

function PrintVerify() { 
    if(xmlHttp.readyState==1) {   
        //document.getElementById("pa_print").innerHTML="";
        //document.getElementById("pa_print").innerHTML="<div align='center'><img src='./images/loader-1.gif'/><br><label >Verifying...  </label></div>"; 
    }
    if(xmlHttp.readyState==4) { 
        document.getElementById("pa_print").innerHTML="";
        document.getElementById("pa_print").innerHTML=xmlHttp.responseText;
        frames['frame1'].print();
    }//end of else
}

服务器页面:p_Print.php:

<iframe src="pa_print.php?cono=<?=$contno ?>" name='frame1'></frame>

谁能帮我解决这个问题,我无法打印 iframe 的内容

【问题讨论】:

    标签: php javascript html ajax


    【解决方案1】:

    尝试导航 iframe (frm.src='new_script.php'),而不是 ajax + 设置 innerhtml。然后在 iframe 中加载的页面上,钩住 onload 事件并打印页面。

    【讨论】:

    • 你能详细描述一下吗,我真的没明白
    • 实际上这适用于 mozilla,但当我在 google chrome 上运行时打印空白....
    • 不要使用AJAX加载iframe内容,然后将iframe内部html设置为ajax调用返回的内容,而是尝试直接将iframe的src设置为您尝试使用ajax加载的URL .然后,在iframe中加载的页面中,使用window.onload事件打印
    猜你喜欢
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    相关资源
    最近更新 更多