JS在firefox

时间:2016-05-18 07:25:53

标签: javascript java jquery firefox applet

我正在使用qzprint API在我的开放式购物车扩展程序中打印标签。一切都很好,但突然间它停止了FF的工作。在Internet Explorer中它工作正常。如果我在我的applet函数中添加警报,它在firefox上工作正常,但不确定为什么不用警报。这是我的代码。

在我的header.tpl中调用applet函数

<script type="text/javascript">
deployQZ('<?php echo HTTP_CATALOG ?>');
useDefaultPrinter();
<script>

包含功能的Applet文件

function deployQZ(path) {
//alert("alert for printing label");
    pathApplet = path + 'java/qz-print.jar';
    pathJnlp = path + 'java/qz-print_jnlp.jnlp';
    var attributes = {id: "qz", code:'qz.PrintApplet.class', 
        archive: pathApplet, width:1, height:1};
    var parameters = {jnlp_href: pathJnlp, 
        cache_option:'plugin', disable_logging:'false', 
        initial_focus:'false'};
    if (deployJava.versionCheck("1.7+") == true) {}
    else if (deployJava.versionCheck("1.6+") == true) {
        attributes['archive'] = 'java/jre6/qz-print.jar';
        parameters['jnlp_href'] = 'java/jre6/qz-print_jnlp.jnlp';
    }
    deployJava.runApplet(attributes, parameters, '1.5');
}

/**
* Automatically gets called when applet has loaded.
*/
function qzReady() {
    // Setup our global qz object
    window["qz"] = document.getElementById('qz');
    //var title = document.getElementById("title");
    if (qz) {
        try {
            //title.innerHTML = title.innerHTML + " " + qz.getVersion();
            //document.getElementById("content").style.background = "#F0F0F0";
        } catch(err) { // LiveConnect error, display a detailed meesage
            document.getElementById("content").style.background = "#F5A9A9";
            alert("ERROR:  \nThe applet did not load correctly.  Communication to the " + 
                "applet has failed, likely caused by Java Security Settings.  \n\n" + 
                "CAUSE:  \nJava 7 update 25 and higher block LiveConnect calls " + 
                "once Oracle has marked that version as outdated, which " + 
                "is likely the cause.  \n\nSOLUTION:  \n  1. Update Java to the latest " + 
                "Java version \n          (or)\n  2. Lower the security " + 
                "settings from the Java Control Panel.");
      }
  }
}

    /**
* Returns is the applet is not loaded properly
*/
function isLoaded() {
    if (!qz) {
        alert('Error:\n\n\tPrint plugin is NOT loaded!');
        return false;
    } else {
        try {
            if (!qz.isActive()) {
                alert('Error:\n\n\tPrint plugin is loaded but NOT active!');
                return false;
            }
        } catch (err) {
            alert('Error:\n\n\tPrint plugin is NOT loaded properly!');
            return false;
        }
    }
    return true;
}

    function useDefaultPrinter() {
    //alert("alert for printing label");
    if (isLoaded()) {
        // Searches for default printer
        qz.findPrinter();

        // Automatically gets called when "qz.findPrinter()" is finished.
        window['qzDoneFinding'] = function() {
            // Alert the printer name to user
            var printer = qz.getPrinter();
            //alert(printer !== null ? 'Default printer found: "' + printer + '"':
                //'Default printer ' + 'not found');
            document.getElementById("name_printer").innerHTML = 'Default printer found: "' + printer + '"'; 
            // Remove reference to this function
            window['qzDoneFinding'] = null;
            defaultFound = true;
        };
    }
}

正如你在我的deployqz()和usedefaultprinter()函数中看到的那样,我在第一行有警报,如果注释它在fire fox中不起作用,如果没有评论,那么它在评论中工作正常。使用注释我从isLoaded()函数获取警告消息“打印插件未正确加载!”。

同样在我的控制台中我得到了这个

使用document.write()编写了一个不平衡的树,导致重新分析来自网络的数据。有关详细信息https://developer.mozilla.org/en/Optimizing_Your_Pages_for_Speculative_Parsing

1 个答案:

答案 0 :(得分:0)

试试这个:

  1. 如果applet在准备就绪时调用了qzReady,请将useDefaultPrinter放在该函数中。
  2. 如果isLoaded需要一些时间,请使用setTimeout调用useDefaultPrinter
  3. 喜欢这个

    <script type="text/javascript">
    deployQZ('<?php echo HTTP_CATALOG ?>');
    <script>
    

    包含功能的Applet文件

    var qz;
    
    function deployQZ(path) {
        pathApplet = path + 'java/qz-print.jar';
        pathJnlp = path + 'java/qz-print_jnlp.jnlp';
        var attributes = {id: "qz", code:'qz.PrintApplet.class', 
            archive: pathApplet, width:1, height:1};
        var parameters = {jnlp_href: pathJnlp, 
            cache_option:'plugin', disable_logging:'false', 
            initial_focus:'false'};
        if (deployJava.versionCheck("1.7+") == true) {}
        else if (deployJava.versionCheck("1.6+") == true) {
            attributes['archive'] = 'java/jre6/qz-print.jar';
            parameters['jnlp_href'] = 'java/jre6/qz-print_jnlp.jnlp';
        }
        deployJava.runApplet(attributes, parameters, '1.5');
    }
    
    /**
    * Automatically gets called when applet has loaded.
    */
    function qzReady() {
        // Setup our global qz object
        qz = document.getElementById('qz');
        if (qz) {
            try {
              useDefaultPrinter();
            } catch(err) { // LiveConnect error, display a detailed meesage
                document.getElementById("content").style.background = "#F5A9A9";
                alert("ERROR:  \nThe applet did not load correctly.  Communication to the " + 
                    "applet has failed, likely caused by Java Security Settings.  \n\n" + 
                    "CAUSE:  \nJava 7 update 25 and higher block LiveConnect calls " + 
                    "once Oracle has marked that version as outdated, which " + 
                    "is likely the cause.  \n\nSOLUTION:  \n  1. Update Java to the latest " + 
                    "Java version \n          (or)\n  2. Lower the security " + 
                    "settings from the Java Control Panel.");
          }
       }
       else { setTimeout(useDefaultPrinter,300); }
    }
    
        /**
    * Returns is the applet is not loaded properly
    */
    function isLoaded() {
        if (!qz) {
            alert('Error:\n\n\tPrint plugin is NOT loaded!');
            return false;
        } else {
            try {
                if (!qz.isActive()) {
                    alert('Error:\n\n\tPrint plugin is loaded but NOT active!');
                    return false;
                }
            } catch (err) {
                alert('Error:\n\n\tPrint plugin is NOT loaded properly!');
                return false;
            }
        }
        return true;
    }
    
    function useDefaultPrinter() {
        //alert("alert for printing label");
        if (isLoaded()) {
            // Searches for default printer
            qz.findPrinter();
    
            // Automatically gets called when "qz.findPrinter()" is finished.
            window['qzDoneFinding'] = function() {
                // Alert the printer name to user
                var printer = qz.getPrinter();
                //alert(printer !== null ? 'Default printer found: "' + printer + '"':
                    //'Default printer ' + 'not found');
                document.getElementById("name_printer").innerHTML = 'Default printer found: "' + printer + '"'; 
                // Remove reference to this function
                window['qzDoneFinding'] = null;
                defaultFound = true;
            };
        }
        else { setTimeout(useDefaultPrinter,300); }
    }
    
相关问题