繁体   English   中英

资源文件和Java类的Javascript绝对路径

[英]Javascript absolute path to resource file and java class

我正在关注旧的JavaScript教程(本书),因此使其无法正常工作。 操作系统是Windows 7/84,IDE是Netbeans 8.02。 浏览器是IE 11,以及最新版本的Chrome和Firefox。

这是代码:

<HTML>
    <HEAD><TITLE>Detecting embedded objects (applets, plug-ins, etc.)</TITLE>

        <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- Hide from browsers that do not support JavaScript
            function detectPlugins() {
                if (navigator.plugins.length > 0) {
                    var pluginDescription = "";

                    for (var numPlugins = 0; numPlugins < navigator.plugins.length; numPlugins++) {
                        pluginDescription = pluginDescription + " " + navigator.plugins[numPlugins].name
                    }

                    alert(navigator.plugins.length + " browser plug-ins detected: "
                            + pluginDescription);

                }
                else {
                    alert("No browser plug-ins detected. (Remember, IE doesn't support plug-ins.)")
                }

            }


            function detectApplets() {
                if (document.applets.length > 0) {
                    alert(document.applets.length + " Java applets detected. (Rememember, IE counts applets as embedded objects.)")

                }
                else {
                    alert("No Java applets detected.")
                }
            }

            function detectEmbeds() {

                if (navigator.appName == "Microsoft Internet Explorer") {
                    // The user is running IE, so check for objects
                    // embedded using the OBJECT tag.
                    //
                    // The readyState property of an object embedded
                    // using the OBJECT property can contain one of 3
                    // values:
                    // 0 = uninitialized
                    // 1 = loading
                    // 4 = finished loading and ready to go

                    if (document.QTsample.readyState == 4) {
                        alert("Detected the QTsample embedded object");
                    }

                    if (document.clock.readyState == 4) {
                        alert("Detected the clock embedded object");
                    }

                }
                else {
                    if (navigator.appName == "Netscape") {


                        if (document.embeds.length > 0) {
                            alert(document.embeds.length + " embedded object(s) detected.")


                        }
                        else {
                            alert("No embedded objects detected.");
                        }
                    }
                }
            }

            // --> Finish hiding
        </SCRIPT>

    </HEAD>
    <BODY>
        Two embedded objects appear below:
        <OL>
            <LI><b>A sample movie provided free by QuickTime (Sample.mov).</b>
                Note: IE identifies applets as objects. IE does not recognize browser plug-ins. (IE supports
                ActiveX objects instead of plug-ins.)
            <LI><b>A sample Java applet provided free by Sun Microsystems (JavaClock.class)</b>
                Note: Navigator identifies applets as applets.
        </OL>

        <!--
        You use the OBJECT tag to embed an ActiveX component into a page meant for MSIE;
        you use the EMBED tag to embed a plug-in into a page meant for Navigator.
        Notice the difference between the way the value of the SRC
        variable must be specified.
        // -->

        <OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320" HEIGHT="250"
                ID="QTsample" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">
            <PARAM name="SRC" VALUE="C:\Program Files (x86)\QuickTime\Sample.mov">
            <PARAM name="AUTOPLAY" VALUE="true">
            <PARAM name="CONTROLLER" VALUE="true">

            <EMBED SRC="file://C:\Program Files (x86)\QuickTime\Sample.mov" WIDTH="320" HEIGHT="250" 
                   AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/">
        </OBJECT>

        <!--
        This Java applet is freely available from Sun Microsystems.  For more info, visit http://java.sun.com/openstudio/applets/clock.html
        Note: the APPLET tag was deprecated in HTML 4.0, which means that programmers are encouraged to use the OBJECT tag
        (instead of the APPLET tag) to embed Java applets in Web pages. Future browsers may not support the APPLET tag.
        // -->

    <APPLET ID="clock" CODEBASE="classes" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">
        <PARAM  NAME="bgcolor"  VALUE="FFFFFF">
        <PARAM  NAME="border"   VALUE="5">
        <PARAM  NAME="ccolor"   VALUE="dddddd">
        <PARAM  NAME="cfont"    VALUE="TimesRoman|BOLD|18">
        <PARAM  NAME="delay"    VALUE="100">
        <PARAM  NAME="hhcolor"  VALUE="0000FF">
        <PARAM  NAME="link"     VALUE="http://java.sun.com/">
        <PARAM  NAME="mhcolor"  VALUE="00FF00">
        <PARAM  NAME="ncolor"   VALUE="000000">
        <PARAM  NAME="nradius"  VALUE="80">
        <PARAM  NAME="shcolor"  VALUE="FF0000">
    </APPLET>
    <P>
    <FORM>
        <INPUT TYPE="button" VALUE="detect embedded objects" onClick="detectEmbeds()">
        <INPUT TYPE="button" VALUE="detect plug-ins" onClick="detectPlugins()">
        <INPUT TYPE="button" VALUE="detect applets" onClick="detectApplets()">
    </FORM>
</BODY>
</HTML>

最初在书本上的路径是:

<PARAM name="SRC" VALUE="c:\Program Files\QuickTime\Sample.mov">

<EMBED SRC="file://c:\Program Files\QuickTime\Sample.mov" WIDTH="320"
HEIGHT="250" AUTOPLAY="true" CONTROLLER="true"
PLUGINSPAGE="http://www.apple.com/quicktime/download/">

所以我更改了它以反映Windows 7 64位程序路径。 没用 然后,我将Sample.mov移到C:\\ Sample.mov并更新了代码中的路径,但是那也不起作用吗? 然后,我将Sample.mov移到了html所在的文件夹中,将路径更新为仅包含“ C:\\”的“ Sample.mov”。 而且有效。 在此之前,我尝试了所有可能的组合(/或//或\\或file:/// C:/ ...等)。 但是,它只有没有任何路径才能起作用。

因此,为了使IE和Firefox中都可以打开QuickTime视频,我得出了以下结论:

<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320" HEIGHT="250"
        ID="QTsample" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">
    <PARAM name="SRC" VALUE="Sample.mov">
    <PARAM name="AUTOPLAY" VALUE="true">
    <PARAM name="CONTROLLER" VALUE="true">

    <EMBED SRC="Sample.mov" WIDTH="320" HEIGHT="250" 
           AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/">
</OBJECT>

问题1是:我应该如何处理位于文档根目录之外的文件,就像在真实示例中那样。

不幸的是,我无法使Java Clock工作。 我也尝试了每种组合,但是浏览器只是不“看到” JavaClock类? 不管我是否从IDE(直接从浏览器(IE,Firefox或Chrome)打开HTMK页面的Netbeans)中进行调整,浏览器都在抱怨JavaClock.class不存在?

问题2是:如何使JavaClock类也能正常工作?

文件位于此屏幕快照上: 在此处输入图片说明

我只是发现错误的位置(这是本书的作者):它应该是(对于CODEBASE) 而不是

它应该是:

<APPLET ID="clock" CODEBASE="class" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">

代替

<APPLET ID="clock" CODEBASE="classes" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">

现在可以(即使在本地计算机上):

在此处输入图片说明

暂无
暂无

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

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