saimaz
saimaz

Reputation: 301

$.fancybox.close() not working

I know that question was discussed plenty of times, but i tried all suggestions and noone didn't work. I am using fancybox with href atribute where content is loading using ajax.

$('a').fancybox(
        {
            href:'ajax/test.php',
            titleShow:false
        }); 

And in content i had custom close button

<a href="javascript:void(1)" title="close" onclick="$.fancybox.close()">Pirkti prekes</a>

And when i click that i got $.fancybox is undefined.

Upvotes: 2

Views: 31648

Answers (5)

Hossein Hashemi
Hossein Hashemi

Reputation: 150

I use below code. It works generally

$('.fancybox-close').click();

Upvotes: 0

Oleg  Beat
Oleg Beat

Reputation: 337

sometimes i have the same problem, and use:

parent.$('body').fancybox.close();

or

$('body').fancybox.close();

or

 $.fancybox.close();

Upvotes: 2

pnairn
pnairn

Reputation: 2017

I think your problem is because you're loading the ajax content into an iframe?

Try

<a href="javascript:;" onclick="parent.$.fn.fancybox.close();">Close</a>

Also, the following works for me as well when using the same selector that was used to initialize fancybox in my page header script.

<a href="javascript:;" onclick="$('a.myclass').fancybox.close();">Close</a>

Where a.myclass was used as the selector for the fancybox as follows

$("a.myclass").fancybox({
  'frameWidth':  920,
  'frameHeight':  705 //with whatever other attributes you want to define
});

EDIT: See the Fancybox Google Group http://groups.google.com/group/fancybox/browse_thread/thread/a6eaf87875b93829

Upvotes: 2

Kimtho6
Kimtho6

Reputation: 6184

Instead of making a onclick it should look like

$('a').click(function(){
 $(this).fancybox.close();
});

Upvotes: 2

cusimar9
cusimar9

Reputation: 5259

I'm not sure about the fancybox, but your href attribute should just be a '#' with a 'return false' at the end of your onclick handler.

Upvotes: 2

Related Questions