开发者

$.fancybox.close() not working

开发者 https://www.devze.com 2023-02-15 06:46 出处:网络
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 usin开发者_运维问答g ajax.

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 usin开发者_运维问答g 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.


Instead of making a onclick it should look like

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


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.


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


sometimes i have the same problem, and use:

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

or

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

or

 $.fancybox.close();


I use below code. It works generally

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

精彩评论

暂无评论...
验证码 换一张
取 消