Free Jobs
Reference




Java Forums: Core Java (15) J2EE (3) EJB (5) Servlet (3) JDBC (6) Hibernate (2) Struts (1) Swing (1) Oracle (7) JSP (4) Other (10)

Topic: How an applet can call a javascript function on its parent page

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share





User: jennifer100 Post Date: 25 Jan 2012 09:01

Introduction:
How an applet can call a javascript function on its parent page



Main Content:
The netscape.javascript.JSObject class can be used  by Java applets

 to get a reference to JavaScript objects.

Suppose below is the javascript function that has to be called by applet.

<script language="javascript">

    var customerName = "";

    function getcustomerAge() {

        return 40;

    }

</script>



 



Below is the applet code that will be calling javascript function

getcustomerAge above.

import java.applet.Applet;

import netscape.javascript.*;

JSObject window = JSObject.getWindow(this);

String customerName = "Sample Name";

window.setMember("customerName", customerName);

Number customerAge = (Number) window.eval("getcustomerAge()");



Conclusion:
thus an applet can call a javascript function on its parent page



About Writer:
Hi,I am working as JAVA Team Lead in an MNC in Bangalore.


Writer's Link:

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)