how to make cookie work?

会有一股神秘感。 提交于 2019-12-12 05:04:25

问题


I'm really stuck with cookie and working on it for two days and i do not know what to do and i try a lot stuff i read online .I'm trying to create a cookie which is expiring in 30 sec .if the users refresh the page between this 30 sec the popup should not pop just once when the users are entering in the page they should see the popup and cookie is expiring in 30 sec if the users refresh the page after 30 sec they should see it . my first problem is that my cookie is expiring after 4 hours even i put 30 sec i really do not know whats the problem.second problem is keep poping up it does not stop .if you can help me with it you are making my day .

<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Bootstrap Core CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <!-- Latest jQuery Library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <!-- Bootstrap Core JS -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  <!-- Cookie JS for Modal -->
  <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.min.js"></script>
  <script type="text/javascript">
	$(document).ready(function(){
		$("#myModal").modal('show');
		
	});
	
	
</script>
<script>
   function createCookie(name) {
   debugger;
   var date = new Date();
   date.setTime(date.getTime()+(30*1000));
  // alert(date);
   var expires = "; expires="+date.toGMTString();
   document.cookie = name+"="+expires+"; path=/";
//alert(document.cookie);
}
function showbanner()
{
document.write('<div class="container-fluid"><div id="myModal" class="modal fade">    <div class="modal-dialog">        <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h3>REGISTER FOR FALL SESSION</h3></div><div class="modal-body"><div class="row"><div class="col-xs-12 col-sm-6"> <img src="gym.png" alt="gym_promo" style="width:304px;"></div><div class="col-xs-12 col-sm-6"><h3> Reserve Your Spot Today </h3><p> EMAIL : <a href="mailto:PLAYATGYM@GMAIL.COM" target="_top">PLAYATGYM@GMAIL.COM </a> </p><p>OR CALL :<a href="514-795-4266"> 514-795-4266</a> </p> </div></div></div> </div> </div></div></div>');
 
}
  </script>
  

</head>

<body>
<script>
var ban = document.cookie;

createCookie('banner');
if(ban==""){
showbanner();
}

</script>


  

</body>
</html>                            

来源:https://stackoverflow.com/questions/46100092/how-to-make-cookie-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!