如何检查fancybox是否已在页面上存在 [英] how to check if fancybox exists on page already

查看:84
本文介绍了如何检查fancybox是否已在页面上存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查fancybox是否已加载.如果是这样,那么我运行ajax脚本将内容放入其中.

I am trying to check if a fancybox has been loaded already. If so then I run an ajax script to put content inside.

如果没有,我打开一个fancybox iframe并获取内容.

If not I open a fancybox iframe and it fetches content.

这是代码:

if ($('div#fancybox-frame:empty').length >0) { 
    alert('it is empty');

$.fancybox({
   'width': '80%',
    'height': '80%',
    'autoScale': true,
    'transitionIn': 'fade',
    'transitionOut': 'fade',   
    'type': 'iframe', 
    'href': '/show_photo'
});
 }
 else{
    alert('it is full');   
    $.ajax({
        type: "GET",
        url: "/show_photo",
        success: function(data){
        cropping_arrived();
        }
    });
  }
});

即使我知道没有打开花哨盒,它总是返回它已满的情况.

It always returns that it is full even when I know there is not fancybox open.

有什么想法吗?

推荐答案

这无需测试.length

if ($('div#fancybox-frame:empty'))

但是,:empty确实检查文本节点.因此,如果您div有换行符,即

However, :empty does check for text nodes. So if you div has a line break, i.e.,

<div id="#fancybox-frame">
</div>

它可能会窒息.在这种情况下,请将开始标签和结束标签放在同一行.

it might choke. In that case, place the opening and closing tags on the same line.

这篇关于如何检查fancybox是否已在页面上存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆