jgok222
jgok222

Reputation: 414

Windows.print displaying print dialog box but printing blank page in fire fox

I am using classic asp, on one page I am using the window.print() method to print a page. The script I am using displays the print dialog box and will print fine in IE however with FF it just prints a blank page

If I use control + p to print the page in fire fox then the page is printed without a problem so its not a rendering problem

here is the script I am using:

function printform(url) {

    var windowReference = window.open(url, "Header", 'width=600,height=600,toolbar=no,resizable=yes,scrollbars=yes,menubar=no');
    if (window.print)
        windowReference.print()
}

Thanks in advance.

This is a work around i came up with thanks to Prusse

function printform(url) {

var windowReference = window.open(url, "Header", 'width=600,height=600,toolbar=no,resizable=yes,scrollbars=yes,menubar=no');
if (window.print)
    if (navigator.appName == "Netscape") {

  windowReference.onload = function(){ windowReference.print(); } 
}
else {
    windowReference.print()
}

}

Upvotes: 1

Views: 5271

Answers (1)

Prusse
Prusse

Reputation: 4315

It stopped working because IE already has loaded the document and already fired the onload event. You could check if the document is already loaded and simply call print and if it isn't and the event handler.

function printform(url) {
    var windowReference = window.open(url, "Header", 'width=600,height=600,toolbar=no,resizable=yes,scrollbars=yes,menubar=no');
    //if (window.print)
    //  windowReference.print();
    if (windowReference.print){
        var done = false;
        if (windowReference.document && windowReference.document.readyState){
            var rs = windowReference.document.readyState;
            if ((rs === 'complete') || (rs === 'loaded')){
                done = true;
                windowReference.print();
            }
        }
        if (!done){
            if (windowReference.addEventListener){
                windowReference.addEventListener('load', function(){ this.print(); });
            } else{
                windowReference.onload = function(){ this.print(); };
            }
        }
    }
}

Upvotes: 4

Related Questions