Ramesh Jn
Ramesh Jn

Reputation: 1

window.print doesn't execute more than once

function prompter() {
    var NoS = prompt("Enter How many Stamp Papers Do you want?", "1");

    for (i = 0; i < NoS; i++) {
        if (i != 0) {
            document.getElementById('sno').value = parseInt(document.getElementById('sno').value) + 1;
        }
        //window.print();
        //var printwindow=window.open('','','left=0,top=0,width=1000,height=780,toolbar=0,scrollbars=0,status=0');
        window.print();
        //var printdata=document.getElementById('printarea').innerHTML;

        //printwindow.document.write();                      
        //printwindow.document.close();
        //window.focus();

        //window.close(); 
    }
    window.history.go(-1);
}

It is working with ECLIPSE IDE browser, but it is not working with external browsers, it is printing only once.

Upvotes: 0

Views: 881

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075527

You have no control of (or view into) the printing process in any cross-browser fashion. window.print just starts the process, typically opening a dialog box the user interacts with. I'm not surprised calling it repeatedly doesn't have the desired result.

I don't think you can do what you want to do. If you need to offer them something different for each copy (the sno value), you'll have to have them print one, click a button to get the next, print that, click a button to get the next, etc.

Or alternately, output all of the ones they want to a window they print just once, but pagination becomes tricky. :-)

Upvotes: 1

Related Questions