473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Javascript using Java methods

Hi all.

Can Java classes/objects be used from within the javascript code on the
HTML page?
I.e., can I call a Java method from the javascript function?
Thanks in advance

Anna

Jul 23 '05 #1
2 1551


annie wrote:

Can Java classes/objects be used from within the javascript code on the
HTML page?
I.e., can I call a Java method from the javascript function?


If you embed a Java applet e.g.
<applet name="appletName" code="applet.class"></applet>
then in some browsers you can call the public methods of that applet e.g.
document.applets.appletName.methodName();
It however depends on the browser and the used Java virtual machine
whether that works, if you use the Sun JRE for Java and browsers like
Mozilla 1.4 or later, Opera 7, IE 5/6 on Windows then it works, IE on
Win with the MS Java VM should also work. I think it doesn't work with
MSIE/Mac while the latest Safari versions are reported to support
JavaScript-->Java applet communication.

In Mozilla and in Opera with the Sun JRE you can also directly script
Java, I have only tested that on Windows, but there you can do e.g.
var javaDate = new java.util.Date();
but that doesn't work with MSIE, whatever Java (Sun or MS) you use.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Hi,

annie wrote:
Hi all.

Can Java classes/objects be used from within the javascript code on the
HTML page?
I.e., can I call a Java method from the javascript function?
Thanks in advance

Anna


In Mozilla, you can.

Example:

netscape.security.PrivilegeManager.enablePrivilege (
"UniversalFileRead" );

var flCheck = new java.io.File( strFullPath );
bFileExists = flCheck.exists();

Or:

netscape.security.PrivilegeManager.enablePrivilege (
"UniversalFileWrite" );
var fsOutput = new java.io.FileOutputStream( strFullPath );
var flOutput = new java.io.DataOutputStream( fsOutput );

flOutput.writeBytes( strContent );

flOutput.flush();
fsOutput.close();
On other browsers, one solution is to pack your Java classes in an
applet and to use LiveConnect (if supported) to access the applet's
public classes.

See
http://www.galasoft-lb.ch/myjavascri...LiveConnect102

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.