简体   繁体   English

Cookie时,JavaScript显示无用

[英]Javascript display none doesn't work while cookie

Live site- http://www.uposonghar.com/test/test_popup.html 实时网站-http : //www.uposonghar.com/test/test_popup.html

I add JavaScript cookie with that popup so if anyone click on "Click Here if don't want to see this Again!" 我在该弹出窗口中添加了JavaScript cookie,因此如果有人单击“如果不想再次看到此内容,请单击此处!”。 button then cookie will be stored, if cookie is stored then popup will not appear for him/her. 按钮,则将存储cookie,如果存储了cookie,则不会为他/她显示弹出窗口。

Once i click on that button cookie stored successfully, popup(id-myModal) disappear but popup bg/overlay(id- reveal-modal-bg) appears. 一旦我单击成功存储的按钮cookie,popup(id-myModal)就会消失,但会弹出bg / overlay(id-reveal-modal-bg)。 i add that code but that doesn't work- 我添加了该代码,但这不起作用-

if(getCookie('abc')=="def" && document.getElementById('myModal'))
   document.getElementById('myModal').style.display="none";
   document.getElementById('reveal-modal-bg').style.display="none";

There is a css on js page, maybe that overwrite my display:none as display:block - http://www.uposonghar.com/test/jquery.reveal.js js页面上有一个CSS,也许覆盖了我的display:none作为display:block - http display:block //www.uposonghar.com/test/jquery.reveal.js

Code of js page- js页面代码

if(options.animation == "none") {
                    modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
                    modalBG.css({"display":"block"});   
                    unlockModal()               
                }

Full code- 完整代码-

<script type="text/javascript">

        function setCookie(c_name,value,exdays)
        {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value + ";path=/";
        }

        function getCookie(c_name)
        {
        var c_value = document.cookie;
        var c_start = c_value.indexOf(" " + c_name + "=");
        if (c_start == -1)
          {
          c_start = c_value.indexOf(c_name + "=");
          }
        if (c_start == -1)
          {
          c_value = null;
          }
        else
          {
          c_start = c_value.indexOf("=", c_start) + 1;
          var c_end = c_value.indexOf(";", c_start);
          if (c_end == -1)
          {
        c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start,c_end));
        }
        return c_value;
        }


        if(getCookie('abc')=="def" && document.getElementById('myModal'))
        document.getElementById('myModal').style.display="none";
        document.getElementById('reveal-modal-bg').style.display="none";
</script>

Can you change the javascript in jquery.reveal.js to 您可以将jquery.reveal.js中的javascript更改为

                if(options.animation == "fadeAndPop" && getCookie('abc')!="def") {
                    modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
                    modalBG.fadeIn(options.animationspeed/2);
                    modal.delay(options.animationspeed/2).animate({
                        "top": $(document).scrollTop()+topMeasure + 'px',
                        "opacity" : 1
                    }, options.animationspeed,unlockModal());                   
                }
                if(options.animation == "fade" && getCookie('abc')!="def") {
                    modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
                    modalBG.fadeIn(options.animationspeed/2);
                    modal.delay(options.animationspeed/2).animate({
                        "opacity" : 1
                    }, options.animationspeed,unlockModal());                   
                } 
                if(options.animation == "none" && getCookie('abc')!="def" ) {
                            modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
                            modalBG.css({"display":"block"});   
                            unlockModal()               
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM