te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - parent.jQuery.fancybox.close(); from within Fancybox only closes Fancybox once - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - parent.jQuery.fancybox.close(); from within Fancybox only closes Fancybox once - Stack Overflow

programmeradmin2浏览0评论

I'm trying to close a Fancybox instance from a link within the Fancybox content. I'm using parent.jQuery.fancybox.close(); as remended in this question. It works the first time, but thereafter not. Can anyone suggest a fix?

I'm hiding my content div in the page with this:

#content {
    display: none;
}

And here's the link launching the Fancybox, with that content div, which includes the link to close the Fancybox.

<a href="#" id="launch">Launch</a>

<div id="content">
    <p>Nunc porttitor pellentesque magna a pulvinar. Vestibulum id diam lectus. Praesent vel dictum est.</p>

    <a href="#" id="close">Close</a>
</div>

And this is my JS. I've tried adding the event hander to the close link on opening the Fancybox, but it didn't help.

$(document).ready(function(){
    $('#launch').fancybox({
        'width': 300,
        'content': $('#content'),
        'onClosed':function () {
            $("#content").hide();
        },
        'onStart':function () {
            $("#content").show();
            $('#close').on('click', function(){
                //console.log($(this).parent);
                parent.jQuery.fancybox.close();
            })
        },
        'onCleanup':function () {
            $("#content").unwrap();
        }
    });
})

Thanks guys!

I'm trying to close a Fancybox instance from a link within the Fancybox content. I'm using parent.jQuery.fancybox.close(); as remended in this question. It works the first time, but thereafter not. Can anyone suggest a fix?

I'm hiding my content div in the page with this:

#content {
    display: none;
}

And here's the link launching the Fancybox, with that content div, which includes the link to close the Fancybox.

<a href="#" id="launch">Launch</a>

<div id="content">
    <p>Nunc porttitor pellentesque magna a pulvinar. Vestibulum id diam lectus. Praesent vel dictum est.</p>

    <a href="#" id="close">Close</a>
</div>

And this is my JS. I've tried adding the event hander to the close link on opening the Fancybox, but it didn't help.

$(document).ready(function(){
    $('#launch').fancybox({
        'width': 300,
        'content': $('#content'),
        'onClosed':function () {
            $("#content").hide();
        },
        'onStart':function () {
            $("#content").show();
            $('#close').on('click', function(){
                //console.log($(this).parent);
                parent.jQuery.fancybox.close();
            })
        },
        'onCleanup':function () {
            $("#content").unwrap();
        }
    });
})

Thanks guys!

Share Improve this question edited May 23, 2017 at 12:30 CommunityBot 11 silver badge asked Mar 15, 2012 at 17:29 And FinallyAnd Finally 5,70414 gold badges73 silver badges112 bronze badges 6
  • So what happens if you just put the $('#close').on() function outside of the .fancybox() function? – Sparky Commented Mar 15, 2012 at 17:55
  • Same thing Sparky - the lightbox closes the first time you launch it, but not after that. – And Finally Commented Mar 15, 2012 at 18:00
  • I guess I don't fully understand what you're trying to do. I use fancyBox and never had any problems like yours. According to the fancyBox documentation, I can't even find the onClosed, onStart or onCleanup methods. – Sparky Commented Mar 15, 2012 at 18:16
  • Thanks Sparky, maybe I'm using a different version - I'll investigate. So you can close Fancyboxes programmatically? – And Finally Commented Mar 15, 2012 at 18:24
  • As simple as $.fancybox.close(); – Sparky Commented Mar 15, 2012 at 18:26
 |  Show 1 more ment

2 Answers 2

Reset to default 7

parent.jQuery.fancybox.close(); should be called from within an iframe opened in fancybox. In your case you are opening inline content so the prefix parent is not needed. Additionally you must provide the correct structure to your inline content and call the closing function from there.

So your inline content should look like

<div style="display: none;">
 <div id="content">
   <p>Nunc porttitor pellentesque magna a pulvinar. Vestibulum id diam lectus. Praesent vel dictum est.</p>
   <a href="javascript:;" id="close">Close</a>
 </div>
</div>

because of the above you don't need this css

#content {
    display: none;
}

since #content is already inside a hidden div.

then your closing function can be separated from the fancybox script... also notice the changes on the fancybox script below:

$(document).ready(function(){
 $('#close').on('click', function(){
  //console.log($(this).parent);
  $.fancybox.close();
 }); //on
/*
// you could also do 
$('#close').click(function(){
 $.fancybox.close();
});
*/
 $('#launch').click(function(){
  $.fancybox({
   'width': 300,
   'href': '#content',
   'onCleanup':function () {
    $("#content").unwrap();
   }
  });//fancybox
 }); // click
}); //ready

this is for Fancybox v1.3.x, the version you seem to be using. Also you should be using jQuery v1.7.x if you want the .on() method to work.

    try{
        parent.jQuery.fancybox.close();
    }catch(err){
        parent.$('#fancybox-overlay').hide();
        parent.$('#fancybox-wrap').hide();
    }

!!!Not Support onClose!!!

发布评论

评论列表(0)

  1. 暂无评论