// Simple example of calling JavaScript from a loaded web page. import iexplorer.InternetExplorer; import iexplorer.IWebBrowserApp; import mshtml.IHTMLDocument; import ezjcom.JComObject; import ezjcom.JComVariant; import java.io.BufferedReader; import java.io.InputStreamReader; public class JavaScriptSample { static String url = TBD: specify your URL string here (in quotes); public static void main(String args[]) { IWebBrowserApp app = null; try { // Instantiate an InternetExplorer InternetExplorer ie = new InternetExplorer(); // Get IWebBrowserApp app = ie.getIWebBrowserApp(); // Make the browser visible app.setVisible( true ); // If IE is trying to load any default pages, stop it. app.Stop(); System.out.println( "Page loading stopped successfully" ); // Attach the events listener. WebLoadListener webLoadListener = new WebLoadListener(); ie.addJComEventListener( webLoadListener ); webLoadListener.initialize(); synchronized ( webLoadListener ) { app.Navigate( url ); webLoadListener.wait(); } // Get the "Script" object for calling JavaScript IHTMLDocument doc = (IHTMLDocument) app.getDocument().JComCoerceObjectToAnotherType( IHTMLDocument.class ); JComObject script = doc.getScript(); // Now we can call JavaScript methods using the script variable. script.JComCallMethod( "alert", new JComVariant[]{ new JComVariant( "Hello, there!" ) } ); System.out.print( "Press ENTER to exit program" ); BufferedReader in = new BufferedReader( new InputStreamReader( System.in )); in.readLine(); } catch (Exception ex) { ex.printStackTrace(); } finally { if ( app != null ) try { // If Internet Explorer has been initialized, cause it to exit. app.Quit(); } catch (Exception ex) { } } System.exit( 1 ); } }