简体   繁体   English

如何在另一个目录中包含来自网页的小程序?

[英]How to include an applet from a web page in a different directory?

I'm trying to use the jZebra printing applet and am not sure how to use it from pages in different directories. 我正在尝试使用jZebra打印applet,并且不确定如何从不同目录中的页面使用它。 The sample page has the following code: 该示例页面具有以下代码:

<applet 
    id="qz"
    name="QZ Print Plugin"
    code="qz.PrintApplet.class"
    width="55"
    height="55">
    <param name="jnlp_href" value="qz-print_jnlp.jnlp">
    <param name="cache_option" value="plugin">
    <param name="disable_logging" value="false">
</applet>

If the applet (qz-print.jar) and another file (qz-print_jnlp.jnlp) are in the same directory as the page with that code, then it works fine. 如果小程序(qz-print.jar)和另一个文件(qz-print_jnlp.jnlp)与包含该代码的页面位于同一目录中,则可以正常工作。 However, I don't know what to change to get it to work if the web page is in a different directory. 但是,如果网页位于其他目录中,我不知道要进行哪些更改才能使其正常工作。 It seems like this is a trivial question, but I've been searching and haven't been able to find the answer. 看来这是一个琐碎的问题,但我一直在搜索,但找不到答案。

How should I modify the above code to get the applet in the web page when it's in a different directory? 当小程序位于其他目录中时,如何修改上面的代码以使小程序进入网页?

The tag you are using: 您正在使用的标签:

<param name="jnlp_href" value="qz-print_jnlp.jnlp">

Is the equivalent of this: (notice the "./"): 等效于:(注意“ ./”):

<param name="jnlp_href" value="./qz-print_jnlp.jnlp">

Java uses absolute or relative paths, just as an image tag would <img src="./foo.png /> Java使用绝对或相对路径,就像图像标记<img src="./foo.png />

So, if you've placed your applet in one folder called "dist" (ie http://mysite/dist/qz-print.jar ) but your page was located in another folder called "web"(ie http://mysite/web/mypage.html ) then you would have to change your relative applet tag to this: 因此,如果您将小程序放置在一个名为“ dist”的文件夹中(即http://mysite/dist/qz-print.jar ),但是您的页面位于另一个名为“ web”的文件夹中(即http://mysite/web/mypage.html ),则必须将相对的applet标签更改为:

<param name="jnlp_href" value="../dist/qz-print_jnlp.jnlp">

Or optimally, change the tag to be absolute path to the jnlp: 或最佳地,将标签更改为jnlp的绝对路径:

<param name="jnlp_href" value="/dist/qz-print_jnlp.jnlp">

Additionally, as qz finds better ways to load these tags, we put them in the sample.html. 此外,由于qz找到了加载这些标签的更好方法,我们将它们放在sample.html中。 I would recommend you use the latest version from here . 我建议您使用此处的最新版本。

At the time of writing this, the best way to use the tags is this way: <applet id="qz" archive="./qz-print.jar" name="QZ Print Plugin" code="qz.PrintApplet.class" width="55" height="55"> <param name="jnlp_href" value="qz-print_jnlp.jnlp"> <param name="cache_option" value="plugin"> <param name="disable_logging" value="false"> <param name="initial_focus" value="false"> <param name="separate_jvm" value="true"> </applet><br /> 在撰写本文时,使用标签的最佳方法是: <applet id="qz" archive="./qz-print.jar" name="QZ Print Plugin" code="qz.PrintApplet.class" width="55" height="55"> <param name="jnlp_href" value="qz-print_jnlp.jnlp"> <param name="cache_option" value="plugin"> <param name="disable_logging" value="false"> <param name="initial_focus" value="false"> <param name="separate_jvm" value="true"> </applet><br />

Note that the archive tag should be updated as well as the jnlp tag. 请注意,存档标签和jnlp标签也应更新。

The three changes from the sample you are using to the sample I've provided above are: 从您正在使用的示例到我上面提供的示例的三个更改是:

  1. Initial focus stealing prevention for jQuery focus() events jQuery focus()事件的初始焦点窃取预防
  2. The archive= tag for compatibility with certain versions of Safari. archive=标记,用于与某些版本的Safari兼容。
  3. The separate_jvm tag is used to load a new instance of the Java Framework on page load, which seems to resolve some sporadic loading issues with Java 8. separate_jvm标记用于在页面加载时加载Java Framework的新实例,这似乎解决了Java 8的一些零星加载问题。

Finally, if you have clients that still run Java 6, I would advise you use deployQZ(); 最后,如果您的客户端仍在运行Java 6,我建议您使用deployQZ(); from sample.html instead, which does Java client version detection using Oracle's deployJava.js script. 而是来自sample.html,它使用Oracle的deployJava.js脚本进行Java客户端版本检测。

-Tres -Tres

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM