views:

4530

answers:

4

Hi all i want to be able to close fancyBox when it is open from within.

I have tried the following but to no avail:

function closeFancyBox(html){
 var re = /.*Element insert complete!.*/gi;
 if( html.search( re ) == 0 ){
  $.fancybox.close();
  //alert("foo");
 }
}

foo will open in dialog but will not close down. any hints?

+8  A: 

According to http://fancybox.net/faq

  1. How can I close FancyBox from other element? ?

Just call $.fn.fancybox.close() on your onClick event

So you should just be able to add in the fn.

Justin Johnson
Haha... I look at the source, you look FAQ. +1 for you being smarter :)
Doug Neiner
i have tried that, still not working...
Phil Jackson
no errors, no other framework libs.
Phil Jackson
+1 worked for me
Tony
+2  A: 

Use this to close it instead:

$.fn.fancybox.close();

Judging from the fancybox source code, that is how they handle closing it internally.

Doug Neiner
i have tried that, still not working...
Phil Jackson
+1  A: 

It is no use putting the .fn, it will reffers to the prototype.
What you need to do is $.fancybox.close();

The thing is that you are maybe experiencing another error from js.
There are any errors on screen?
Is your fancybox and jquery the latest releases? jquery is currently in 1.4.1 and fb in 1.3 something

Experiment putting a link inside the fancybox and put that function in it.

You probably had read that, but in any case, http://fancybox.net/api

One thing that you probably might need to do is isolate each part in order to realize what it is.

NoProblemBabe
But this method isn't removing the back-ground div. It just close the box.
Zote
If your background hasn't been removed, then either you created that background and forced, somehow fancybox to use it, or you are experiencing an error on your js, somewhere in the moment that the fancy box is closing. Perhaps you need to try something bold: open the fancy box js file, and put alerts naming each part of that function. The one that not opens, is the line that gives the error. You can, also in other approach, use a try catch statement, and show or write the error as soon as it happens. Just in case, here is how to use it: http://www.w3schools.com/jS/js_try_catch.asp. Good luck.
NoProblemBabe
Just to add some more info: Some js errors that happen to happen in runtime, sometimes are not shown in error logs, if you force it to re-throw the exception, they usually are caught by the error logs.
NoProblemBabe
+3  A: 

Try this: parent.$.fancybox.close();

difrnt
I had trouble with $.fancybox.close(), but this worked for me.
rrrhys
yeah this one worked for me :) thanks
JT.WK