What is this "Unknown Name" JSException in Internet Exlorer 6?

836 Views Asked by At

I am using JSObject to invoke a Javascript function from my Applet.

SSCCE of my Applet:

package ch.vrag.web;

import java.applet.Applet;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.Policy;

import netscape.javascript.JSObject;

public class Sscce extends Applet {

private static final long serialVersionUID = -5403444704039831864L;

public void init() {
    try {
        Policy.setPolicy(new Policy() {
            Permissions perms = new Permissions();

            public PermissionCollection getPermissions(CodeSource codesource) throws SecurityException {
                AllPermission grant = null;
                grant = new AllPermission();
                perms.add(grant);
                return perms;
            }

            public void refresh() {
                // Do nothing
            }
        });
    }
    catch (Exception e) {
    }

    JSObject window = JSObject.getWindow(this);

    JSObject phoneNums = (JSObject) window.eval("getWindowRectangle()");

    int x;
    int y;
    int width;
    int height;

    if (phoneNums.getSlot(0) instanceof Integer) {
        x = (Integer) phoneNums.getSlot(0);
        y = (Integer) phoneNums.getSlot(1);
        width = (Integer) phoneNums.getSlot(2);
        height = (Integer) phoneNums.getSlot(3);
    }
    else if (phoneNums.getSlot(0) instanceof Double) {
        x = ((Double) phoneNums.getSlot(0)).intValue();
        y = ((Double) phoneNums.getSlot(1)).intValue();
        width = ((Double) phoneNums.getSlot(2)).intValue();
        height = ((Double) phoneNums.getSlot(3)).intValue();
    }
    else {
        return;
    }

    System.out.println("x: " + x + " y: " + y + " width: " + width + " height: " + height);

};
}

An SSCCE of my HTML File:

 <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <script type="text/javascript">
        function getWindowRectangle(){

            var winX = (document.all)?window.screenLeft-2:window.screenX;
            var winY = (document.all)?window.screenTop-2:window.screenY;

            var winWidth = (document.all)?document.documentElement.offsetWidth+4:window.outerWidth;
            var winHeight = (document.all)?document.documentElement.offsetHeight+4:window.outerHeight;

            return([winX,winY,winWidth,winHeight]);
        }       
    </script>

    <title>SSCCE</title>
</head>
<body>
    this is an SSCCE
    <APPLET CODE="ch.vrag.web.Sscce.class" name="SSCCE" codebase="scripts" archive="Sscce.jar" width=0 height=0 MAYSCRIPT >
    </APPLET>
</body>

This works great exept in Internet Explorer 6. There I have this Java Exception:

java.lang.Exception: netscape.javascript.JSException: Unknown Name

what is this Exception good for? What am I doing wrong?

3

There are 3 best solutions below

0
Neifen On BEST ANSWER

The Internet Explorer 6 seems to have a Problem with the getSlot() command, but I could use a Workaround.

with this Object:
JSObject phoneNums = (JSObject) window.eval("getWindowRectangle()");

I can get a String out of phoneNumbs (phoneNums.toString();) this String gives me my return values in this form:

"number1,number2,number3,number4"

so I can split the string and get the numbers I need.

The moral of the story is, that Internet Exlorer 6 is not no contemporary and should not be used any more!

3
jn1kk On

It has to do with the browser not being to run Javascript properly. Make sure IE6 is patched to the SV3 version and Javascript is enabled along with the security setting possible.

2
Andrew Thompson On

At the bottom of Read/Write HTML field values from Java is the fine print:

For best result, never use LiveConnect JSObject in Applet's init() method.

The reason being it is commonly null at that point. I've had more success obtaining a reference to the JSObject in the applet start() method.


JSObject phoneNums = (JSObject) window.eval("getWindowRectangle()");

I suspect this should be JSObject.call("getWindowRectangle()") instead. Do some debugging on the returned Object, inspect it in a debugger to check the content is as you expect.