2 Replies Latest reply: Jun 29, 2011 1:14 PM by 802711 RSS

    Java Applet won't load when a JavaScript variable "this.Document" is used.

    802711
      Hi,

      Creating a "this.Document" variable within JavaScript interferes with some versions of Java. So far it breaks on the following versions, using IE7 on Windows XP:
      * JRE 6.0 Update 7
      * JRE 6.0 Update 6
      * JRE 6.0 Update 5
      * JRE 6.0 Update 4
      [Due to time constraints JRE 6.0 to JRE 6.0 Update 3 were not tested]
      * JRE 5.0 Update 22
      [Due to time constraints JRE 5.0 Update 16 to JRE 5.0 Update 21 were not tested]
      * JRE 5.0 Update 15
      [Due to time constraints JRE 5.0 Update 1 to JRE 5.0 Update 14 were not tested]
      * JRE 5.0

      The following HTML demonstrates this problem when you have any of the above versions of Java installed:
      <html>
          <head>
              <title>Java Bug</title>
              <script type="text/javascript" language="javascript">
                  this.Document = 'string'; // Remove this line to get it to work again
              </script>
          </head>
          <body style="background-color:black">
              <applet id="testVM" alt="Something is wrong. Java is not working." 
                  codebase="http://www.java.com/applet" code="testJava2_1/TestVMApplet" 
                  archive="TestVM2-test.jar" width="500" height="280">
                  <param name="locale" value="en" />    
                  <param name="titleSize" value="22" />
                  <param name="subtitleSize" value="18" />    
              </applet>
          </body>
      </html>
      The page only displays a white box where the Java Applet should be. If you then remove the "this.Document" variable or simply rename it to something else then the applet loads without problems. Normally I would just use a different variable name but the variable name is placed within the Mootools JavaScript Framework and is not easily changed without forking my own project.

      Does anyone know why this happens and if it can be fixed without having to update to the latest version of Java?

      Thanks
        • 1. Re: Java Applet won't load when a JavaScript variable "this.Document" is used.
          EJP
          'this.document' is a predefined variable that defines the URL source of the current page. Your name either conflicts with that or is getting confused with it somewhere. Use another name.
          • 2. Re: Java Applet won't load when a JavaScript variable "this.Document" is used.
            802711
            EJP wrote:
            'this.document' is a predefined variable that defines the URL source of the current page.
            If you are referring to the predefined variable that provides access to the Document Object Model then I believe you are mistaken, that is 'window.document' or just 'document'.
            EJP wrote:
            Your name either conflicts with that or is getting confused with it somewhere.
            The 'document' variable is a parent of the window object e.g. 'window.document' but my variable has the context of 'this'. That means 'this.document.URL' returns 'undefined' instead of the URL for the current page.

            JavaScript is also case sensitive so 'document.URL' is not the same as 'Document.URL', the last of which returns 'undefined'.

            If Java relealy was confusing my variable with the predfined one then I would expect the same behaviour if I were to use differnt variations of the variable. However the follwoing JavaScript doesnt affect the Applet in anyway:
            <script type="text/javascript" language="javascript">
                //this.Document = 'string'; // Remove this line to get it to work again
                this.document = 'string';
                document = 'string'; 
                Document = 'string';             
            </script>
            For some strange reason it only affects the Applet when 'this.Document' is used. Why would Java be affected in this way in the first instance? Even setting the 'scriptable' parameter to false doesn’t help:
            <param name="scriptable" value="false">
            Are there any other settings I am not aware of that could maybe prevent Java from loooking at the JavaScript?
            EJP wrote:
            Use another name.
            As I mentioned in my original post this is not easily done, I can edit the source code on my own site but the code still remains unchanged on the Mootools JavaScript Framework website.

            Thanks