tags:

views:

393

answers:

2

I'm struggling to find a way to hide a java applet () using jquery.

I have a link that opens up a simple ajax fancybox (http://fancybox.net) problem is that it always appears 'behind' the actual java applet.

Is there a way to 'hide' the applet or even unload it ? I can reload it after closing the fancybox (basically asking for user confirmation).

Thanks

+1  A: 

You can remove it's DOM object, or set it's CSS property to hidden.

jQuery("#applet").remove();

or

jQuery("#applet").hide();

You can also kill the applet:

 <script>
 document.MyApplet.killApplet();
 </script>

 public void killApplet() 
 {
    AccessController.doPrivileged(new PrivilegedAction() 
   {

        public Void run() {
            // kill the JVM
            System.exit(0);
            return null;
        }
    });
 }

However, this stops the applet, and throws JS errors in IE6

You can also set the applets size to (1,1), and set it back when you're finished.

jQuery("#applet").height(1).width(1);
Malfist
Ok, .hide() works. But when I put 'show' it doesn't show it back
Disco
Try a show on the applet itself instead of it's DIV
Malfist
i have : <applet id="myapplet"> and then $("#myapplet").hide() works, but $("#myapplet").show() doesn't.
Disco
Flash has this problem too, you set the Window Mode to transparent for it. Don't know if you can do this with Java Applets or not.
Malfist
mmmh ... is there a way to tell jquery to 'change' the applet src ? that could solve the problem
Disco
jQuery("#applet").attr("src", "null");
Malfist
mmh seems a bug of fancy box : $(document).ready(function(){ $("a#ajax").fancybox({ 'onStart': function() { alert ('opened');}, 'onClosed': function() { alert ('closed'); } });});onclosed is never displayed.
Disco
So trigger it yourself :) jQuery("fancybox").trigger("closed");
Malfist
i'm really new to jquery; what is the 'trigger' supposed to do ? how to use it ?
Disco
trigger triggers an event handler. You can use it to cause custom events. http://api.jquery.com/trigger/ For example, if I did jQuery("#button").tigger("click") it would fire the click event of the button.
Malfist
ok I see but i need to do some action when user clicks on the close button of fancybox; onClosed function doesn't seem to work (http://fancybox.net/api)
Disco
manage the click event for the close button
Malfist
+1  A: 

Try something like this:

var save=$('#applet').clone();
$('#applet').html('');

and when You need it back

$('#applet').html(save.html());
save=null; //to free this bit of memory

not tested, but I expect it to work ;)

naugtur
Ok will give a try, thx.
Disco