在 IE 中从 Java 调用 JavaScript 函数时出现访问被拒绝异常
当我仅在 IE 中从 Java Applet 调用 Java 脚本函数时,出现访问被拒绝异常。 (用更新的信息修改了我原来的问题。)
这是我的 HTML 代码
<script type="text/javascript">
function uploadComplete() {
alert("in Upload Complete");
ju.doneUpload(true);
}
</script>
ju
在同一页面中全局声明,该页面从不同的 JavaScript 文件调用 didUpload。我已将 MAYSCRIPT 包含在我的小程序标签中。
Java 代码 [添加 AccessController 后] :
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
JSObject scriptObject = getScriptObject(uploadDialogBox.applet);
if(scriptObject != null) {
try {
// this is the call where it throws an exception
**scriptObject.call("uploadComplete", null);**
} catch(JSException e) {
System.out.println("exception " + e.getMessage()
+ " WrappendException " + e.getWrappedException()
+ " stack trace " + e.getStackTrace());
}
}
return null;
}
});
private JSObject getScriptObject(JApplet appletInstance) {
JSObject result = null;
// JSObject doc = null;
try {
result = JSObject.getWindow(appletInstance);
// doc = (JSObject) result.getMember("document");
} catch (JSException e) {
System.out.println("Exception in getScriptObject : " + e.getMessage()
+ " Wrappend exception " + e.getWrappedException());
}
return result;
}
它抛出 JSException:访问被拒绝
未调用 uploadComplete
中的 alert
函数。我在这里做错了什么?
I am getting Access Denied exception when I am calling a Java Script Function from Java Applet only in IE. ( modified my original question with updated information.)
Here is my HTML code
<script type="text/javascript">
function uploadComplete() {
alert("in Upload Complete");
ju.doneUpload(true);
}
</script>
ju
is declared globally in the same page which calls the doneUpload from a different JavaScript file. I have included MAYSCRIPT in my applet Tag.
Java Code [After adding AccessController] :
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
JSObject scriptObject = getScriptObject(uploadDialogBox.applet);
if(scriptObject != null) {
try {
// this is the call where it throws an exception
**scriptObject.call("uploadComplete", null);**
} catch(JSException e) {
System.out.println("exception " + e.getMessage()
+ " WrappendException " + e.getWrappedException()
+ " stack trace " + e.getStackTrace());
}
}
return null;
}
});
private JSObject getScriptObject(JApplet appletInstance) {
JSObject result = null;
// JSObject doc = null;
try {
result = JSObject.getWindow(appletInstance);
// doc = (JSObject) result.getMember("document");
} catch (JSException e) {
System.out.println("Exception in getScriptObject : " + e.getMessage()
+ " Wrappend exception " + e.getWrappedException());
}
return result;
}
It throws an JSException: Access is denied
The alert
function in uploadComplete
is not called. What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有帮助吗?
Sun 论坛上的回答摘要:
您好,我遇到了同样的问题。我解决了,你只需要实现这样的小程序方法:
这种方法的唯一问题是,当你第一次调用方法时,需要很长时间才能响应(4-5秒),并且每次调用时,响应是立即。
编辑:好的,第二个可能的解决方案是使用 getDocument(),如 这篇文章。需要警告的是,在我们的测试中,我们发现这在 Mac 上的 Firefox 上并不总是可靠。这个方法的本质是做:
Does this help?
A summary from that answer on the Sun forums:
Hello, I had same problem. I solved it, you just need to implement applets method like this:
The only problem with this approach is that when you call method for the first time, it takes pretty long time to respond (4-5s), and every next time, response is immediately.
Edit: OK, a second potential solution is to use getDocument() as described in this article. One word of warning, in our testing, we have seen that this is not always reliable on Firefox on the Mac. The essence of this method is to do: