Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript call to Java Applet method does not work only in Chrome browser
    text
    copied!<p>I'm trying to run a small test of an applet to call a JavaScript method and vice-versa. The code works fine in IE 9.0 and Firefox 17.0, but does not work in Chrome 23.0.1271.91 m.</p> <p>I'm not sure if it is a problem of this specific version of Chrome , but I guess not.</p> <p>Basically, I have a main HTML page, that declares the applet using an 'object' tag, and also with a 'iframe' tag. In another file, I have a HTML page that will be loaded in the iframe from the main page, but commanded by the applet.</p> <p>In the main.html file I'm using 'object' tag instead of 'applet' to be compliant with HTML5. I know this test should work using 'applet' tag, but use the 'applet' tag is exactly what I'm trying to avoid.</p> <p>The applet code:</p> <pre><code>package tests.javaplugin; import java.applet.Applet; import java.util.*; import netscape.javascript.JSObject; public class PluginTestApplet extends Applet { private static final long serialVersionUID = 492358995598940846L; private static Timer theTimer = new Timer(true); private static JSObject theWindow; @Override public void init() { System.out.println("entering init()"); theWindow = JSObject.getWindow(this); System.out.println("exiting init()"); } public void loadComplete() { System.out.println("calling loadComplete()"); theTimer.schedule(new ShowPageTimerTask(), 100); System.out.println("returning loadComplete()"); } public int getRandomInteger() { System.out.println("calling getRandomInteger()"); final int random = (int) Math.abs(Math.random() * 100); System.out.println("returning getRandomInteger(): " + random); return random; } private class ShowPageTimerTask extends TimerTask { @Override public void run() { System.out.println("entering ShowPageTimerTask.run()"); theWindow.call("showPage", new String[] { "./page.html" }); System.out.println("exiting ShowPageTimerTask.run()"); } } } </code></pre> <p>The main.html code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="windows-1252"&gt; &lt;title&gt;Testing Java Plug-in in Java 7.0&lt;/title&gt; &lt;script src="./mainControl.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body onload="onBodyLoad()"&gt; &lt;!--[if !IE]&gt;--&gt; &lt;object id="applet_embed" width="0" height="0" type="application/x-java-applet;version=1.7"&gt; &lt;!--&lt;![endif]--&gt; &lt;!--[if IE]&gt; &lt;object id="applet_embed" width="0" height="0" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"&gt; &lt;![endif]--&gt; &lt;param name="archive" value="PluginTestApplet.jar"&gt; &lt;param name="codebase" value="./"&gt; &lt;param name="code" value="tests.javaplugin.PluginTestApplet"&gt; &lt;param name="scriptable" value="true"&gt; &lt;param name="mayscript" value="true"&gt; No Java 2 SDK, Standard Edition v 1.7 support for APPLET! &lt;/object&gt; &lt;div id="principalDIV" style="position: absolute; width: 640px; height: 480px; top: 0px; left: 0px; scrolling: no; visibility: visible; z-index: 0; overflow: hidden; leftmargin=0px; topmargin=0px; background-color: #000000"&gt; &lt;iframe id="ifPrincipal" style="position: absolute; width: 100%; height: 100%; visibility: visible; scrolling: no; overflow-x: hidden; overflow-y: hidden;"&gt; &lt;/iframe&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The mainControl.js code:</p> <pre><code>function getApplet() { return document.getElementById("applet_embed"); } function onBodyLoad() { getApplet().loadComplete(); } function getRandomInteger() { return getApplet().getRandomInteger(); } function showPage(aURL) { var iframePrincipal = document.getElementById("ifPrincipal"); if (iframePrincipal.src != null) { iframePrincipal.src = aURL; } else { alert("Error! iframe src = null! " + iframePrincipal.src); } } </code></pre> <p>The page.html code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="windows-1252"&gt; &lt;title&gt;Testing Java Plug-in in Java 7.0&lt;/title&gt; &lt;script src="./control.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body onload="onBodyLoad()" style="background-color: #000000; color: #ffffff; font-family: Tahoma; font-size: 35px;" &gt; &lt;div&gt;Testing dynamic HTML i-frame commanded by Java Plug-in.&lt;/div&gt; &lt;div style="float: left;"&gt;The random number is&amp;nbsp;&lt;/div&gt;&lt;div id="randomNum" style="float: left;"&gt;&amp;nbsp;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The control.js code:</p> <pre><code>function onBodyLoad() { var randomNumber = parent.getRandomInteger(); var randomNumberDiv = document.getElementById("randomNum"); randomNumberDiv.innerHTML = randomNumber; } </code></pre> <p>The console (in development tools) presents these errors:</p> <pre><code>Uncaught TypeError: Object #&lt;HTMLObjectElement&gt; has no method 'loadComplete' mainControl.js:6 Failed to load resource file:///C:/Projects/Tests/javaplugintest/tests.javaplugin.PluginTestApplet </code></pre> <p>So, there are any trick or specific parameter in 'object' tag declaration needed for Chrome?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload