【问题标题】:Javascript Fancybox 2 close button/link event not workingJavascript Fancybox 2关闭按钮/链接事件不起作用
【发布时间】:2012-09-21 14:45:07
【问题描述】:

我正在使用 Fancybox 2 创建一个条款和条件弹出窗口,显示当用户登录我们的 wordpress 网站时,从 div 标签中检索此内容并使用 php 从 wordpress 页面中查找正确的内容。他们需要点击一个接受按钮来继续并关闭弹出窗口,这个链接是在 div 标签内生成的。使用单独的 php 文件,他们的用户 id 被添加到一个表中,表明他们已经接受了 ts 和 cs。除接受按钮外,一切正常。当我单击接受链接时,窗口没有完全关闭,它停留在屏幕上,但是当我的表使用用户 ID 更新时触发了 onclose 事件。当我单击内容(包括链接)的任意位置时,我可以看到窗口快速进出。所以我猜fancybox顶部有某种不可见的覆盖层,阻止了链接被执行?

这是我的代码

<a class="fancybox" href="test" style="display:none;">ddd</a>
        <div id="test" style="display:none;height:600;width:750px;">
                        <?php
        global $blog_id,$wpdb;
        // query the DB to retrieve the post 'termsofservice' from the localized sites posts table
        $tnc_notification = $wpdb->get_var( $wpdb->prepare( "select post_content from wp_posts where post_title='Terms & Conditions' and post_status='publish';" ) );
            echo "<p>TERMS and CONDITIONS have changed, please read the new terms and conditions.  By closing this window you automatically accept them</p>";

                    echo '<a href="javascript:jQuery.fancybox.close();">Accept </a> ';

                    echo "<p>".$tnc_notification."</p>";
        ?>

<script type="text/javascript" language="javascript">
function callTNC(){
            jQuery(document).ready(function() {
                    jQuery("#test").fancybox({
                                                'closeBtn': false,
                                                'closeClick': false,
                                                'modal': true,
                                                'maxHeight': 600,
                                                'maxWidth': 750,
                                                afterClose : function (){
                                                    //add the user into the tnc accepted table
                                                    $.get("http://mysite.com/tncaccept.php");
                                                }
                    }).trigger('click');

            });
}

任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: php javascript wordpress fancybox


    【解决方案1】:

    找到的编辑解决方案: 好的,我设法解决了这个问题。您必须在链接中创建一个引用并在 jQuery(document).ready(function() 声明 所以发生的事情是接受链接/按钮中的javascript没有正确调用fancybox close。

    所以首先在接受链接/按钮中创建引用

    echo '<a href="#" id="closeFancy">Accept</a> ';
    

    然后在fancybox声明/初始化中创建函数:

    <script type="text/javascript" language="javascript">
    function callTNC(){
                jQuery(document).ready(function() { 
                                                jQuery("#closeFancy").click(function(){
                                                    jQuery.fancybox.close();
                                                    return false;
                                                });
                        jQuery("#test").fancybox({
                                                    'closeBtn': false,
                                                    'closeClick': false,
                                                    'modal': true,
                                                    'maxHeight': 600,
                                                    'maxWidth': 750,
                                                    helpers   : { 
                                                        overlay : {closeClick: false} // prevents closing when clicking OUTSIDE fancybox 
                                                    },
    
                                                    afterClose : function (){
                                                        //add the user into the tnc accepted table
                                                        $.get("http://mysite.com/tncaccept.php");
                                                    }
                        }).trigger('click');
                                                //$("#acceptClose").click(function(){
                                                //    $.fancybox.close();
                                                //    return false;
                                                //});
                });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      相关资源
      最近更新 更多