Javascript absolute path to resource file and java class

I am following and old tutorial (from book) for JavaScript and I have some troubles with making it work. OS is Windows 7/84 and IDE is Netbeans 8.02. Browsers are IE 11, and latest versions of Chrome and Firefox.

Here is the code:

<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>

Open in new window


Originally in book paths were like:
<PARAM name="SRC" VALUE="c:\Program Files\QuickTime\Sample.mov">

Open in new window

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

Open in new window

So I changed that to reflect Windows 7 64 bit program path. It didn't work. Then I moved Sample.mov to C:\Sample.mov and updated paths in code as well, but that didn't work either? Then I moved Sample.mov to same folder where is html, updated paths just to "Sample.mov" without "C:\". And it worked. I tried all possible combinations prior to that ( / or // or \ or file:///C:/... etc). But it works only without any path.

So in order to make QuickTime video opening in both IE and Firefox I ended up with this:
<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>

Open in new window

QUESTION 1 IS: how should I make it work with file located outside of document root, like it was supposed in genuine example.

Unfortunately, I can't make java clock work. I also tried every combination but browser just don't "see" JavaClock class? No matter if I tun it from IDE (Netbeans of directly by opening HTMK page from browser (IE, Firefox or Chrome). Browsers are complaining that JavaClock.class doesn't exist?

QUESTION 2 IS: how should I make that JavaClock class work as well?.

Files are located as on this screenshot:
Files location in Netbeans IDEFiles location in Netbeans IDE
KPaxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
You need a new tutorial.  Local absolute paths are not supported in modern browsers.  And most won't open a 'file://' resource from an 'http://' resource.  It's considered a security breach.

And JAVA has had too many security problems in the last year.  These days, even when it is installed properly, you have to go into the Java Console and enable it's use in your web browsers.  The default state is 'disabled'.
0
GaryCommented:
The src values should be the path relative to the site or localhost, you are doing absolute paths on the client which is not allowed (unless you were running the file directly in the browser locally using your own file system)
So the path should be more like you have it removing all paths and just having the movie in the same folder. If in the same directory you had another folder called movies and the .mov file was in that then you path would become

movies/Sample.mov
0
KPaxAuthor Commented:
OK, I understand, I can run QT movie on local machine and it works OK on the web as well, but I can't make that JavaClock class work, browser says it can't find it.
I uploaded all of it here.
How should I make that path for Java class, right now it is:

 <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>

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dave BaldwinFixer of ProblemsCommented:
Here is what I get in Firefox from your page.
EMBEDed ObjectsI would have to install a plugin to run your JAVA.  Although I don't know if it would run even then since I have not enabled JAVA in my browsers.
0
KPaxAuthor Commented:
Here is what it looks like when you have QuickTime plugin and Java plugin installed:
Screenshot from browser
Clicking on details reveals no useful info, just:

Java Plug-in 10.71.2.14
Using JRE version 1.7.0_71-b14 Java HotSpot(TM) Client VM
User home directory = C:\Users\Nenad
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
0
Dave BaldwinFixer of ProblemsCommented:
I actually do have them installed but the Default in Firefox is to make you enable them when they are requested by a page.  In addition, as I stated above,  JAVA won't run unless you specifically enable it in the JAVA console which is normally found in the Control Panel.
0
KPaxAuthor Commented:
Yes, I know that about JAVA, I am JAVA developer, and even had lots of HTML/CSS/JavaScript programming years and years ago. Meanwhile I was developing JAVA EE and Android apps, and now I want to recall making websites with HTML/CSS/JavaScript/Ajax, so I took my old book from stack and doing all of the tutorials again.  I know how to set web browser and not only that but also how to setup Weblogic or JBoss, or Tomcat or Apache servers (LAMP). So problem is not about JAVA or browser or enabling plugins but simply I can't figure out right now how to handle absolute or relative path in JavaScript.
0
Dave BaldwinFixer of ProblemsCommented:
Javascript (or anything else) in modern browsers is not normally allowed to use absolute paths and in most situations, not allowed to access 'local' paths at all.  Javascript can load image files from the server but normally only from the web root, not above it, and AJAX can do the same.

HTML/CSS/JavaScript programming years and years ago is Not what it is now in terms of file access and restrictions.  Take a look at the View Source of a lot of working pages and you will not see any absolute paths.
0
Dave BaldwinFixer of ProblemsCommented:
You might want to look at this page on Browser Security:  https://code.google.com/p/browsersec/wiki/Part2
0
KPaxAuthor Commented:
No, I just found where the error is (blame to author of the book):
It should be (for CODEBASE) class not classes

It should be:
<APPLET ID="clock" CODEBASE="class" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">

Open in new window


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

Open in new window


Now it is ok (even on local machine):

C:\Users\Nenad\Pictures\My Screen Shots\Screen Shot 12-24-14 at 11.50 PM.PNG
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
Glad you got it figured out.
0
KPaxAuthor Commented:
Trivial error, the worst kind of errors, so much annoying but so easily to be overlooked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.