1. 程式人生 > >Lodop-JS列印-Bootstrap樣式錯亂解決方案

Lodop-JS列印-Bootstrap樣式錯亂解決方案

var CreatedOKLodop7766 = null;

//====判斷是否需要安裝CLodop雲列印伺服器:====
function needCLodop() {
    try {
        var ua = navigator.userAgent;
        if (ua.match(/Windows\sPhone/i) != null) return true;
        if (ua.match(/iPhone|iPod/i) != null) return true;
        if (ua.match(/Android/i) != null) return true;
        if (ua.match(/Edge\D?\d+/i) != null) return true;

        var verTrident = ua.match(/Trident\D?\d+/i);
        var verIE = ua.match(/MSIE\D?\d+/i);
        var verOPR = ua.match(/OPR\D?\d+/i);
        var verFF = ua.match(/Firefox\D?\d+/i);
        var x64 = ua.match(/x64/i);
        if ((verTrident == null) && (verIE == null) && (x64 !== null))
            return true; else
            if (verFF !== null) {
                verFF = verFF[0].match(/\d+/);
                if ((verFF[0] >= 42) || (x64 !== null)) return true;
            } else
                if (verOPR !== null) {
                    verOPR = verOPR[0].match(/\d+/);
                    if (verOPR[0] >= 32) return true;
                } else
                    if ((verTrident == null) && (verIE == null)) {
                        var verChrome = ua.match(/Chrome\D?\d+/i);
                        if (verChrome !== null) {
                            verChrome = verChrome[0].match(/\d+/);
                            if (verChrome[0] >= 42) return true;
                        };
                    };
        return false;
    } catch (err) { return true; };
};

//====頁面引用CLodop雲列印必須的JS檔案:====
if (needCLodop()) {
    var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
    var oscript = document.createElement("script");
    oscript.src = "
http://localhost:8000/CLodopfuncs.js?priority=1
";
    head.insertBefore(oscript, head.firstChild);

    //引用雙埠(8000和18000)避免其中某個被佔用:
    oscript = document.createElement("script");
    oscript.src = "http://localhost:18000/CLodopfuncs.js?priority=0";
    head.insertBefore(oscript, head.firstChild);
};

//====獲取LODOP物件的主過程:====
function getLodop(oOBJECT, oEMBED) {
    var strHtmInstall = "<br><font color='#FF00FF'>列印控制元件未安裝!點選這裡<a href='
http://www.lodop.net/download/Lodop6.215_CLodop2.090.zip
' target='_self'>執行安裝</a>,安裝後請重新整理頁面或重新進入。</font>";
    var strHtmUpdate = "<br><font color='#FF00FF'>列印控制元件需要升級!點選這裡<a href='http://www.lodop.net/download/Lodop6.215_CLodop2.090.zip' target='_self'>執行升級</a>,升級後請重新進入。</font>";
    var strHtm64_Install = "<br><font color='#FF00FF'>列印控制元件未安裝!點選這裡<a href='
http://www.lodop.net/download/Lodop6.215_CLodop2.090.zip
' target='_self'>執行安裝</a>,安裝後請重新整理頁面或重新進入。</font>";
    var strHtm64_Update = "<br><font color='#FF00FF'>列印控制元件需要升級!點選這裡<a href='http://www.lodop.net/download/Lodop6.215_CLodop2.090.zip' target='_self'>執行升級</a>,升級後請重新進入。</font>";
    var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安裝過Lodop舊版附件npActiveXPLugin,請在【工具】->【附加元件】->【擴充套件】中先卸它)</font>";
    var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,僅因瀏覽器升級或重安裝而出問題,需重新執行以上安裝)</font>";
    var strCLodopInstall = "<br><font color='#FF00FF'>CLodop雲列印服務(localhost本地)未安裝啟動!點選這裡<a href='http://www.lodop.net/download/Lodop6.215_CLodop2.090.zip' target='_self'>執行安裝</a>,安裝後請重新整理頁面。</font>";
    var strCLodopUpdate = "<br><font color='#FF00FF'>CLodop雲列印服務需升級!點選這裡<a href='http://www.lodop.net/download/Lodop6.215_CLodop2.090.zip' target='_self'>執行升級</a>,升級後請重新整理頁面。</font>";
    var LODOP;
    try {
        var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
        if (needCLodop()) {
            try { LODOP = getCLodop(); } catch (err) { };
            if (!LODOP && document.readyState !== "complete") { alert("C-Lodop沒準備好,請稍後再試!"); return; };
            if (!LODOP) {
                if (isIE) document.write(strCLodopInstall); else
                    document.documentElement.innerHTML = strCLodopInstall + document.documentElement.innerHTML;
                return;
            } else {

                if (CLODOP.CVERSION < "2.0.9.0") {
                    if (isIE) document.write(strCLodopUpdate); else
                        document.documentElement.innerHTML = strCLodopUpdate + document.documentElement.innerHTML;
                };
                if (oEMBED && oEMBED.parentNode) oEMBED.parentNode.removeChild(oEMBED);
                if (oOBJECT && oOBJECT.parentNode) oOBJECT.parentNode.removeChild(oOBJECT);
            };
        } else {
            var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
            //=====如果頁面有Lodop就直接使用,沒有則新建:==========
            if (oOBJECT != undefined || oEMBED != undefined) {
                if (isIE) LODOP = oOBJECT; else LODOP = oEMBED;
            } else if (CreatedOKLodop7766 == null) {
                LODOP = document.createElement("object");
                LODOP.setAttribute("width", 0);
                LODOP.setAttribute("height", 0);
                LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
                if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
                else LODOP.setAttribute("type", "application/x-print-lodop");
                document.documentElement.appendChild(LODOP);
                CreatedOKLodop7766 = LODOP;
            } else LODOP = CreatedOKLodop7766;
            //=====Lodop外掛未安裝時提示下載地址:==========
            if ((LODOP == null) || (typeof (LODOP.VERSION) == "undefined")) {
                if (navigator.userAgent.indexOf('Chrome') >= 0)
                    document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
                if (navigator.userAgent.indexOf('Firefox') >= 0)
                    document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
                if (is64IE) document.write(strHtm64_Install); else
                    if (isIE) document.write(strHtmInstall); else
                        document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
                return LODOP;
            };
        };
        if (LODOP.VERSION < "6.2.1.5") {
            if (needCLodop())
                document.documentElement.innerHTML = strCLodopUpdate + document.documentElement.innerHTML; else
                if (is64IE) document.write(strHtm64_Update); else
                    if (isIE) document.write(strHtmUpdate); else
                        document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
            return LODOP;
        };
        //===如下空白位置適合呼叫統一功能(如註冊語句、語言選擇等):===
        LODOP.SET_LICENSES("", "13528A153BAEE3A0254B9507DCDE2839", "", "");
        //===========================================================
        return LODOP;
    } catch (err) { alert("getLodop出錯:" + err); };
};