Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Applet-Javascript interaction

I wish for a message on my web page to say "Please wait for the applet to load ...".
[ This text can be shoved into a <div> or some other element if necessary. ]

Once my applet is loaded, I want this message to dissapear (so, removed from the <div> element it's in, for example).

How can I achieve this?


Thanks.
0
InteractiveMind
Asked:
InteractiveMind
  • 3
  • 2
1 Solution
 
TimYatesCommented:
I use this:

  // Cool reflection based javascript calling method
  // Taken from http://www.rgagnon.com/javadetails/java-0172.html
  public String callBrowser( String jsCmd )
  {
    String jsResult = null ;
    boolean success = false ;
    try
    {
      Method getw = null, eval = null ;
      Object jswin = null ;

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

      Method ms[] = c.getMethods() ;
      for( int i = 0 ; i < ms.length ; i++ )
      {
        if( ms[ i ].getName().equals( "getWindow" ) )
          getw = ms[ i ] ;
        else if( ms[ i ].getName().equals( "eval" ) )
          eval = ms[ i ] ;
      }

      Object a[] = new Object[ 1 ] ;

      a[ 0 ] = this ; /* this is the applet */
      jswin = getw.invoke( c, a ) ; /* this yields the JSObject */

      a[ 0 ] = jsCmd ;
      Object result = eval.invoke( jswin, a ) ;

      if( result instanceof String )
        jsResult = (String)result ;
      else
        jsResult = result.toString() ;

      success = true ;
    }
    catch( InvocationTargetException ite )
    {
      jsResult = "" + ite.getTargetException() ;
    }
    catch( Exception e )
    {
      jsResult = "" + e ;
    }

    if(success)
      return jsResult ;
    else
    {
      System.out.println( "eval failed with error " + jsResult ) ;
      return null ;
    }
  }

Then when your applet starts call:

    callBrowser( "document.getElementById( 'theDiv' ).display = 'none'" ) ;

and make sure your div is like:

    <div id="theDiv">Please Wait For Applet to load</div>

Tim
0
 
TimYatesCommented:
you might need to put MAYSCRIPT in your applet tag :-)

Hi Rob btw :-)

Tim
0
 
InteractiveMindAuthor Commented:
Hey Tim,

thanks for that - that works great :-)

Rob.
0
 
TimYatesCommented:
yay :-)

Good luck with it fella :-)

Tim
0
 
InteractiveMindAuthor Commented:
Cheers, Tim :-)

Heads up; I've got a new (unrelated) Q on the way ...  ;-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now