javascript只彈出一次框 再次重新整理不彈出

來源:互聯網
上載者:User

標籤:div   black   red   overlay   amp   nbsp   indexof   gettime   padding   

.開啟頁面自動彈出  當關閉彈框的時候  設定cookie存留時間  再次重新整理頁面判斷cookie是否失效

<html> <head> <meta charset="utf-8" />  <title>LIGHTBOX EXAMPLE</title>   <style>    .black_overlay{ display: none; position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.6; opacity:.60; filter: alpha(opacity=60); }    .white_content { display: none; position: absolute; top: 25%; left: 25%; width: 50%; height: 50%; /*padding: 16px;*/ /*border: 16px solid orange;*/border: 1px solid grey; background-color: white; z-index:1002; /*overflow: auto; */}    </style>    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>   <script>       $( document).ready(function(){  //判斷cookie是否存在    if(document.cookie.length <=0){       one();     }else{      return ‘‘;     }                   });      function one(){     document.getElementById(‘light‘).style.display=‘block‘;    document.getElementById(‘fade‘).style.display=‘block‘    }      function two(){    document.getElementById(‘light‘).style.display=‘none‘;    document.getElementById(‘fade‘).style.display=‘none‘    //關閉彈框是設定cookie    setCookie(‘opop‘,‘lailailai‘,1800)           }    //設定cookie    function setCookie(cname, cvalue, exdays) {     var d = new Date();     d.setTime(d.getTime() + (exdays*24*60*60*1000));     var expires = "expires="+d.toUTCString();     document.cookie = cname + "=" + cvalue + "; " + expires;    }        //擷取cookie    function getCookie(cname) {     var name = cname + "=";     var ca = document.cookie.split(‘;‘);     for(var i=0; i<ca.length; i++) {      var c = ca[i];      while (c.charAt(0)==‘ ‘) c = c.substring(1);      if (c.indexOf(name) != -1) return c.substring(name.length, c.length);     }     return "";    }         </script>  </script></head> <body >   <p>     <a href="javascript:showBg();" onclick="one()">點擊這裡開啟視窗</a>  </p>   <div id="light" class="white_content">    <img src="http://imageavatar.xiangsibang.com/gfs.php?img=9cdbc343a8846bba79b55a7c523f9b4f&w=800" style="width:100%;height:100%;">    <a href="javascript:void(0)" onclick="two()" style="   color:red;margin-top: -50%; position: absolute;float: right;/* margin-right: -34%; */margin-left: 99%;">X</a>  </div>   <div id="fade" class="black_overlay" >   </div> </body> </html>

  

javascript只彈出一次框 再次重新整理不彈出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.