• web 后台打印


        //提交打印
        function sbumitPrint() { 
            printHidden("AppsDSPrintDoub.aspx?type=print");
        }
    

      

    function printFrame(frame, onfinish) {
     
        if (!frame)
            frame = window;
    
        function execOnFinish() {
            switch (typeof (onfinish)) {
                case "string":
                    execScript(onfinish);
                    break;
                case "function":
                    onfinish();
                    break;
            }
            if (focused && !focused.disabled)
                focused.focus();
        }
       
        if (frame.document.readyState !== "complete") {
            execOnFinish();
            return;
        }
    
    //    var eventScope = printGetEventScope(frame);
    //    var focused = document.activeElement;
        window.printHelper = function() {
            //        printWB.ExecWB(6, 2);
            //        printFireEvent(frame, eventScope, "onafterprint");
            //        printWB.outerHTML = "";
            //        execOnFinish();
            //frame.jqprint();
            var prints = $(frame.document.getElementById('printTable')); //打印table的ID
            prints.jqprint();
            window.printHelper = null;
        }
        //document.body.insertAdjacentHTML("beforeEnd", "<object id="printWB" width=0 height=0  classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2">");
        //printFireEvent(frame, eventScope, "onbeforeprint");
        frame.focus();
        window.printHelper();
    }
    
    function printIsNativeSupport() {
        var agent = window.navigator.userAgent;
        var i = agent.indexOf("MSIE ") + 5;
        return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
    }
    
    function printFireEvent(frame, obj, name) {
        var handler = obj[name];
        switch (typeof (handler)) {
            case "string":
                frame.execScript(handler);
                break;
            case "function":
                handler();
                break;
        }
    }
    
    function printGetEventScope(frame) {
        var frameset = frame.document.all.tags("FRAMESET");
        if (frameset.length)
            return frameset[0];
        return frame.document.body;
    }
    
    function printHidden(url) {
      
        document.body.insertAdjacentHTML("beforeEnd", "<iframe name='printHiddenFrame' width='0' height='0'></iframe>");
        var doc = printHiddenFrame.document;
        doc.open();
        doc.write("<body onload="parent.onprintHiddenFrame()">");
        doc.write("<iframe name='printMe' width='0' height='0' src="" + url + ""></iframe>");
        doc.write("</body>");
        doc.close();
    }
    
    function onprintHiddenFrame() {
        function onfinish() {
            printHiddenFrame.outerHTML = "";
            if (window.onprintcomplete)
                window.onprintcomplete();
        }
        printFrame(printHiddenFrame.printMe, onfinish);
    }
    

    这里还要用到一个jqprint-0.3.js 

    // -----------------------------------------------------------------------
    // Eros Fratini - eros@recoding.it
    // jqprint 0.3
    //------------------------------------------------------------------------
    
    (function($) {
        var opt;
    
        $.fn.jqprint = function (options) {
            opt = $.extend({}, $.fn.jqprint.defaults, options);
    
            var $element = (this instanceof jQuery) ? this : $(this);
            
            if (opt.operaSupport && $.browser.opera) 
            { 
                var tab = window.open("","jqPrint-preview");
                tab.document.open();
    
                var doc = tab.document;
            }
            else 
            {
                var $iframe = $("<iframe  />");
            
                if (!opt.debug) { $iframe.css({ position: "absolute",  "0px", height: "0px", left: "-600px", top: "-600px" }); }
    
                $iframe.appendTo("body");
                var doc = $iframe[0].contentWindow.document;
            }
            
            if (opt.importCSS)
            {
                if ($("link[media=print]").length > 0) 
                {
                    $("link[media=print]").each( function() {
                        doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
                    });
                }
                else 
                {
                    $("link").each( function() {
                        doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
                    });
                }
            }
            
            if (opt.printContainer) { doc.write($element.outer()); }
            else { $element.each( function() { doc.write($(this).html()); }); }
            
            doc.close();
            
            (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
            setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000);
        }
        
        $.fn.jqprint.defaults = {
    		debug: false,
    		importCSS: true, 
    		printContainer: true,
    		operaSupport: true
    	};
    
        // Thanks to 9__, found at http://users.livejournal.com/9__/380664.html
        jQuery.fn.outer = function() {
          return $($('<div></div>').html(this.clone())).html();
        } 
    })(jQuery);
    

    可以直接调用jqprint-0.3.js,这样做是为了在提交数据的时候直接打印,等于后台打印,就不要重新打开一个预览页面

  • 相关阅读:
    [leetcode]Reverse Words in a String
    [leetcode]ZigZag Conversion
    [leetcode]Gray Code
    [leetcode]Permutation Sequence
    [leetcode]Next Permutation
    [leetcode]PermutationsII
    [leetcode]Add Two Numbers
    Python与PHP通过XMLRPC进行通信
    最近发现了个js传图预览的函数和大家分享下
    百度地图api2.0体验
  • 原文地址:https://www.cnblogs.com/dragon-L/p/4235300.html
Copyright © 2020-2023  润新知