Sunday, 15 May 2016

Open page in new page and Print div - javascript

No comments


 //Print label

    function PrintLabel(inId) {
        var printLabelContent = "<html><head><title> &nbsp;</title></head><body><label style='font-family:\"Free 3 of 9\"' id='barcodeCode'>" + inId + "</label></br><label style='font-family:\"Arial\"' id='barcodeCodeId'>" + inId + "</label>" + '</body></html>';
        var thePopup = window.open('', "Customer Listing", "menubar=0,location=0,height=700,width=700");            
        thePopup.document.body.innerHTML = printLabelContent;
        var css = '@@page {size: auto;margin: 0; }',
        head = thePopup.document.head || thePopup.document.getElementsByTagName('head')[0],
        style = thePopup.document.createElement('style');
        style.type = 'text/css';
        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
        head.appendChild(style);      
        thePopup.document.getElementById('barcodeCode').style.zoom = "10.0";      
        thePopup.print();
        return false;
    }