JS在firefox中无法正常工作

JS not working properly in firefox

本文关键字:常工作 工作 firefox JS      更新时间:2023-09-26

我使用qzprint API在我的开放式购物车扩展中打印标签。一切都很好,但突然在FF上停止了工作。在Internet explorer中,它工作得很好。如果我在小程序的功能中添加警报,它在firefox上也能很好地工作,但不确定为什么不使用out警报。这是我的密码。

调用我的头中的小程序函数。tpl

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

包含函数的小程序文件

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()函数中看到的那样,我在第一行有警告,如果它被评论了,它在firefox中不起作用,如果没有评论,它就可以正常工作。通过注释,我从isLoaded()函数中得到警告消息"打印插件未正确加载!"。

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

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

试试这个:

  1. 如果qzReady在准备好时被小程序调用,请将useDefaultPrinter放入该函数中
  2. 如果isLoaded需要一些时间,也可以使用setTimeout在其中调用useDefaultPrinter

像这个

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

包含函数的小程序文件

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); }
}