views:

558

answers:

4
function CallPrint() {
        var prtContent = document.getElementById('<%= pnlDelete.ClientID %>');
        var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
        winPrint.document.write("<h3>Summary</h3><br />" + prtContent.innerHTML);
        winPrint.document.close();
        winPrint.focus();
        winPrint.print();
        winPrint.close();
    }

I have a need where I have to print contents of a div. I am using above code to do so. It is working fine in IE but does nothing in Firefox. Am I missing something here that needs to be done in Firefox?

+1  A: 

Uhm... your code seems to work fine for me, on Firefox 3.5 (Windows). It's possible that are something wrong on your pnlDelete.ClientID? Your javascript code is rendered well on the page?

Anyway I suggest you to use jQuery + a print plugin like this.

tanathos
+1  A: 

Check to ensure your panel has something. My guess is prtContent is undefined

Try this:

function CallPrint() {
    var prtContent = document.getElementById('<%= pnlDelete.ClientID %>');

    if (prtContent) {
        var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
        winPrint.document.write("<h3>Summary</h3><br />" + prtContent.innerHTML);
        winPrint.document.close();
        winPrint.focus();
        winPrint.print();
        winPrint.close();
    }
    else {
        alert('No summary available for printing');
    }
}
nickyt
prtContent always has something, I placed an alert to check it...
Utkarsh
A: 

This is the way used to solve my problem, working fine in both IE and Firefox - http://bit.ly/8xHM2l

Utkarsh
sorry? which is the way used to solve the problem? you didn't select an answer. (e.g. your answer should have been a comment added to the answer another user gave that was correct... and mark theirs as correct)
scunliffe
none of the responses provided helped me resolve my problem, I myself was working on it in-between and found a solution which I blogged and provided a link here and marked it as answer.
Utkarsh
A: 

you could try a jquery plugin...

http://plugins.jquery.com/project/PrintArea

Chris R