找到applet调用网页中的javascript的例子:

Netscape only

A Javascript function is called from Java by using the showDocument method. A URL is needed with "javascript:" as the protocol.

[Java applet] import java.applet.*;

import java.net.*;

public class inJava extends Applet{

public void init(){

String msg = "We will jump to an HTML tag";

try {

getAppletContext().showDocument

(new URL("javascript:doAlert("" + msg +"")"));

getAppletContext().showDocument

(new URL("javascript:jumpTo("#JUMP")"));

}

catch (MalformedURLException me) { }

}

}

[Javascript and HTML]

function doAlert(s) {

alert(s);

}

function jumpTo(tag) {

self.location=tag;

}

jump here from Java via Javascript

Netscape AND Microsoft Internet Explorer v4

With IE4, Microsoft included the Netscape package netscape.javascript.* to allow a JAVA applet access to Javascript objects. To compile such Applet, you must adjust the CLASSPATH to include the Netscape java40.jar. To use the Netscape JAR, the CLASSPATH will look like this: set CLASSPATH=

.;c:windevjdk1.1.3libclasses.zip;

c:Program FilesNetscapeCommunicatorProgramJavaClassesjava40.jar;

Note that your CLASSPATH may be different depending on your JDK installation/version

To compile with IE, first locate the javapackages directory in the Windows or WinNt directory. You will find a bunch a zip files with strange names. On my installation (IE5), the file Qk1r3vrp.zip is the one containing the 2 classes you need, JSObject.class and JSException.Class. Include this zip in the classpath before compiling (or you can extract the 2 files (with directory) and create a new smaller ZIP (again with the directory) and use the new zip in the classpath). Note that if you compile with the Microsoft compiler, you don't need to do this.

NOTE: Here, you find will a a JAR containing the required objects to compile classes using the LiveConnect mechanism. This jar file can be used in the CLASSPATH to build MAYSCRIPT applets. Note that the jar is good only at compile time.

In the following example, you type in the TextField a Javascript function and press the button to execute the function. For example, try alert('Hello from JAVA'). Or you can execute function defined on the same page as the Applet. The Applet must contains the MAYSCRIPT parameter to be able to use JSObject. import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import netscape.javascript.*;

public class jsJAVA extends Applet implements

ActionListener {

Button b;

TextField t;

public void init() {

t = new TextField(20);

add(t);

b = new Button("execute Javascript");

add(b);

b.addActionListener(this);

}

public void actionPerformed(ActionEvent ae) {

if (ae.getSource() == b) {

JSObject win = (JSObject) JSObject.getWindow(this);

win.eval(t.getText());

}

}

}

Another way is to use the Reflection API. That way you don't need to modify your CLASSPATH for compilation or even import the netscape.jsobject package. // posted by C Werner on the realhowto list

import java.lang.reflect.*;

...

// Somewhere in the applet class ...

...

String jscmd = "window.close()";  /* JavaScript command */

String jsresult = null;

boolean success = false;

try {

Method getw = null, eval = null;

Object jswin = null;

Class c =

class.forName("netscape.javascript.JSObject"); /* does it in IE too */

Method ms[] = c.getMethods();

for (int i = 0; i

IE中直接访问html,????? help!在IE中用Applet如何访问所在的HTML吗?相关推荐

  1. C++ 在派生类中使用using声明改变基类成员的可访问性

    通过在类的内部使用using声明语句 , 我们可以将该类的直接或间接基类中的任何可访问成员标记出来 (只限于非私有成员) .using声明语句中名字的访问权限由该using声明语句之前的访问说明符来决 ...

  2. Azure中配置网络安全组入站规则让外部网络访问VM中的网站

    今天在azure中搭建了个虚机,虚机的IIS上搭建了个测试网站,然后在虚机内可以正常访问,但是在外部internet却无法访问. 查看了azure的帮助文档,网上也搜了,得到的答案都是设置终结点,az ...

  3. 如何产生签名applet能让applet能够访问本地资源

    2019独角兽企业重金招聘Python工程师标准>>> 如何产生签名applet,以使applet能够访问本地资源? 在jdk1.1中,可以使用javakey命令来产生公钥,私钥,证 ...

  4. java 类的访问权限_什么是Java类的访问权限?

    展开全部 在解32313133353236313431303231363533e59b9ee7ad9431333366306436释访问权限控制之前,先看一个场景. 在学生信息管理系统中,有两个类,分 ...

  5. 计算机d盘被拒绝访问了怎么办,如果硬盘分区被拒绝访问或无法访问该怎么办?...

    拒绝访问硬盘分区的原因可能是硬盘分区表已损坏,导致系统无法正确读取硬盘的分区信息,或者可能是某些软件(例如加密软件)已使用,并且磁盘权限已修改. Bit提供了几种解决方案,请参见下面的具体操作方法: ...

  6. beego 访问网络_Go--Beego新建项目(解决不能访问的问题)

    Go--Beego新建项目(解决不能访问的问题) 博客说明 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢! 说明 beego开发文档 ht ...

  7. 如何跨服务器访问html 页面,html页面如何跨域访问另一页面内容,并将部分内容呈现出来?...

    html代码: 简介 我需要将接口界面的部分内容,显示在id为p4的块中,我自己这边服务器请求是跨域访问,如何操作? jquery ajax来完成,load()方法不能跨域,所以不能用:我自己的代码如 ...

  8. 局域网内计算机无法互相访问,轻松几招解决局域网不能互相访问故障

    经常有网友反映在Win2000和WinXP中浏览网上邻居时很慢,特别是网络中有Win9x和WinMe工作站时尤为明显,有时打开网上邻居甚至需要10多分钟,还经常报错,该如何解决呢?笔者以前也曾遇到过类 ...

  9. 访问服务器显示无法访问目标主机,发送4接收4无法访问目标主机

    大家好,我是时间财富网智能客服时间君,上述问题将由我为大家进行解答. 发送4接收4无法访问目标主机的原因: 1.访问目标所需的跃点数超过了发送方主机为转发数据包而设置的TTL. 2.目标主机无法访问, ...

最新文章

  1. 前端开发学习Day27
  2. openstack用rdo方式安装时遇到的问题
  3. java 文件删除异常 ut_【JAVA-UT】12、抛出了指定的异常吗?
  4. 和谐 平等_平等还是认同?
  5. Matlab控制精度
  6. 前端学习(1986)vue之电商管理系统电商系统之建立新分支
  7. 详解Python对象属性
  8. Android开发之InstanceState详解
  9. 架构师学习笔记(持续更新)
  10. 内网网络摄像机(RTSP/IPC/NVR)如何能在公网进行RTMP/HLS/HTTP-FLV直播
  11. 转载 webstrom识别 React语法
  12. sql语句select group by order by where一般先后顺序
  13. 【渝粤教育】国家开放大学2018年秋季 2711T花卉栽培技术 参考试题
  14. web前端顶岗实习总结报告_web前端年度工作总结范文
  15. matlab随机欠采样,欠采样技术
  16. 服务器接千兆无线网卡,用户吓跑!千兆宽带就是坑爹货:真相崩溃
  17. expandable长点击的实现
  18. 本地计算机添加网络打印机共享,如何连接共享打印机?一步一步教你设置和连接局域网共享打印机...
  19. 趣图:说一说你不知道的世界
  20. Java基础 快速学习(一)

热门文章

  1. spring的maven依赖
  2. Long类型转为String类型
  3. 3500双休和4000单休,你选哪个?
  4. 机顶盒ttl无法输入_中兴盒子连接TTL线后无法输入代码、不跑码乱码的解决方法分享...
  5. 华为云服务权限在哪_华为云资源IAM精细控制权限实践
  6. 超级细菌战:一场人类无法打赢的战争
  7. Elasticsearch:过滤搜索结果 - filter 及 post_filter
  8. [Signal]软阈值与硬阈值
  9. C语言比较两个字符串相等为什么不是用“==”
  10. Qt编写的项目作品5-物联网综合管理平台