views:

102

answers:

1

hi,

i called an iframe using ajax onto the current page and tried to print the page but is printing blank page can somebody help me with this

what i did was: current page:

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

js file function:

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
}

server page: p_Print.php:

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

can somebody help me with this , i am not able to get the contents of the iframe to be printed

+1  A: 

Try to navigate the iframe (frm.src='new_script.php'), instead of ajax + setting the innerhtml. Then on the page loaded in the iframe, hook the onload event and print the page.

SorinV
can u describe it a bit in detail , i really didnt get it
jarus
and thanks for the reply ;)
jarus
actually this works fine with mozilla but prints blank when i run it on google chrome....
jarus
Instead of loading the iframe content using AJAX and then setting the iframe inner html to the content returned by the ajax call, try directly setting the src of the iframe to the URL you are trying to load with ajax.Then, in the page that loads in the iframe, use the window.onload event to print
SorinV