Advertisement
hmbashar

How to use bwowser cookie with click function in jquery

Jan 19th, 2016
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.73 KB | None | 0 0
  1.     <div id="ad">
  2.         <a href=""><img src="http://placehold.it/300x100" alt="Ad" /></a>
  3.     </div>
  4.    
  5.  
  6.     <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
  7.     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
  8. <script>
  9.         jQuery(document).ready(function(){
  10.             if(parseInt(jQuery.cookie('addisplay')) >= 2){
  11.                 jQuery("#ad").hide();
  12.             }
  13.  
  14.             if(jQuery.cookie('addisplay') == null){
  15.                 jQuery.cookie('addisplay', '0', { expires: 7, path: '/' });
  16.             }
  17.  
  18.             var cookieVal = parseInt(jQuery.cookie('addisplay'));
  19.             jQuery("#ad").on("click", function(){
  20.                 jQuery.cookie('addisplay', cookieVal + 1, { expires: 7, path: '/' });
  21.             });
  22.  
  23.         });
  24.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement