弹出的时事通讯延迟

时间:2015-10-12 15:39:07

标签: javascript php html magento

我需要帮助才能实现这一目标。

我有一个magento模板,我的支持期已经过期,但我偶然发现了一个我无法正确纠正的问题。

每当我的网站加载时,时事通讯都会弹出相同的时间,非常烦人。我想要的是在网站加载完成后弹出新闻通讯的延迟。如果可能的话,让它在用户会话期间只出现一次。

如果我能在这里得到帮助,我会很高兴。

非常感谢所有人。

以下是代码

            <?php
            /**
             Made by Smartwave.
             */
            ?>
            <?php
                $store = Mage::app()->getStore();
                $code  = $store->getCode();
                $popup = Mage::getStoreConfig('porto_settings/newsletter_popup',$code);
            ?>
            <script type="text/javascript">
                jQuery(function($) {
                    var check_cookie = $.cookie('newsletter_popup');
                    if(check_cookie == null || check_cookie == 'shown') {
                        beginNewsletterForm();
                    }
                    $('#newsletter_popup_dont_show_again').on('change', function(){
                        if($(this).length){        
                            var check_cookie = $.cookie('newsletter_popup');
                            if(check_cookie == null || check_cookie == 'shown') {
                                $.cookie('newsletter_popup','dontshowitagain');            
                            }
                            else
                            {
                                $.cookie('newsletter_popup','shown');
                                beginNewsletterForm();
                            }
                        } else {
                            $.cookie('newsletter_popup','shown');
                        }
                    }); 
                });

            function beginNewsletterForm() {
                jQuery.fancybox({
                    'padding': '0px',
                    'autoScale': true,
                    'transitionIn': 'fade',
                    'transitionOut': 'fade',
                    'type': 'inline',
                    'href': '#newsletter_popup',
                    'onComplete': function() {
                        $.cookie('newsletter_popup', 'shown');
                    },
                    'tpl': { 
                        closeBtn: '<a title="Close" class="fancybox-item fancybox-close fancybox-newsletter-close" href="javascript:;"></a>' 
                    }
                });
                jQuery('#newsletter_popup').trigger('click');
            }

            </script>
            <style type="text/css">
            <?php
                if($popup["newsletter_custom_style"]){
                    echo $popup["newsletter_custom_style"];
                }
            ?>
            #newsletter_popup{
            <?php
                if($popup["newsletter_width"]){
                    echo "width:".$popup["newsletter_width"].";";
                }
                if($popup["newsletter_height"]){
                    echo "height:".$popup["newsletter_height"].";";
                }
                if($popup["newsletter_bg_color"]){
                    echo "background-color:".$popup["newsletter_bg_color"].";";
                }
                if(isset($popup["newsletter_bg_image"]) && $popup["newsletter_bg_image"]){
            ?>
                background-image:url(<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."porto/newsletter_popup/".$popup['newsletter_bg_image'];?>);
            <?php
                }
            ?>
            }
            </style>
            <div class="block block-subscribe" id="newsletter_popup">
                <form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-popup-validate-detail" onsubmit="setNewsletterCookie()">
                    <div class="block-content">
                        <?php
                            if($popup["show_logo"]){
                        ?>
                                <img src="<?php echo $this->getSkinUrl($popup["show_logo"]); ?>" alt="" />
                        <?php
                            }
                        ?>
                        <?php echo $popup['newsletter_content']; ?>
                        <div class="input-box">
                            <input type="text" name="email" id="newsletter_popup_email" title="<?php echo $this->__('Sign up for our newsletter') ?>" class="input-text required-entry validate-email" placeholder="<?php echo $this->__("Email Address"); ?>" />
                            <button type="submit" title="<?php echo $this->__('Go!') ?>" class="button"><span><span><?php echo $this->__('Go!') ?></span></span></button>
                            <div class="clearer"></div>
                        </div>
                    </div>
                </form>
                <script type="text/javascript">
                //<![CDATA[
                    var newsletterpopupSubscriberFormDetail = new VarienForm('newsletter-popup-validate-detail');
                    document.getElementById("newsletter-popup-validate-detail").onsubmit=function(){
                        jQuery.cookie('newsletter_popup','dontshowitagain');
                    }
                //]]>
                </script>
                <div class="subscribe-bottom">
                    <input type="checkbox" id="newsletter_popup_dont_show_again"/>
                    <label for="newsletter_popup_dont_show_again"><?php echo $this->__("Don't show this popup again"); ?></label>
                </div>
            </div>

1 个答案:

答案 0 :(得分:0)

您可以使用php sleep()功能 缺点:  如果它位于页面的中间,HTML呈现的延迟时间为1秒,则页面渲染时间将延长1秒。 将它放在页面底部。

使用javascript,您可以使用:

setTimeout(function(){ }, 1000);

延迟1秒