Advertisement
Affbuddy

Bootstrap Modal Exit Intent

Aug 21st, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Author: Affbuddy
  5. Site: https://affbuddy.com/
  6. Youtube: https://www.youtube.com/watch?v=cSebDfjrM20
  7. -->    
  8. <head>
  9. <meta charset="UTF-8">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="robots" content="noindex, nofollow">
  12. <title>Javascript Exit Pop Example</title>
  13. <link rel="shortcut icon" href="https://s3.amazonaws.com/affbuddy/favicon.png">
  14. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  15. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
  16. <style>
  17.     @import url(https://fonts.googleapis.com/css?family=Bangers);
  18.     body {
  19.         text-align: center;
  20.     }
  21.     .header {
  22.         margin: auto;
  23.         margin-bottom: 30px;
  24.         padding-top: 10px;
  25.         height: 120px;
  26.         background-color: #2a3a47;
  27.     }
  28.     .logo {
  29.         margin: auto;
  30.         background-image: url(https://s3.amazonaws.com/affbuddy/logo.png);
  31.         background-repeat: no-repeat;
  32.         width: 315px;
  33.         height: 100px;
  34.     }
  35.     .title {
  36.         font-family: 'Bangers', cursive;
  37.         margin-bottom: 60px;
  38.     }
  39.     .panel {
  40.         margin: auto;
  41.         min-height: 300px;
  42.         max-width: 400px;
  43.         border: 6px dashed #ff0000;
  44.         cursor: pointer;
  45.     }
  46.     .panel-body {
  47.         font-size: 20px;
  48.     }
  49. </style>
  50.  
  51. <!--[if IE]>
  52.    <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
  53.    <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
  54. <![endif]-->
  55. </head>
  56.  
  57. <body>
  58. <div class="header">
  59.     <div class="container">
  60.         <div class="logo"></div>
  61.     </div>
  62. </div>
  63.  
  64. <div class="container">
  65.  
  66.     <h1 class="title">Javascript Exit Pop Example</h1>
  67.  
  68.     <div class="panel panel-default" data-href="http://example.com">
  69.       <div class="panel-body">
  70.         <h1>Mega Store Coupon</h1>
  71.         <h2>Save 50% to 90%</h2>
  72.         <br />
  73.         <h2><a href="#">CLICK HERE</a></h2>  
  74.       </div>
  75.     </div>
  76.  
  77. </div><!-- container -->
  78.  
  79. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  80. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
  81.  
  82. <script>
  83. var counter = 2; // number of exit pops before we let them go
  84. function pop() {
  85.     if (counter > 0) {
  86.         counter--;
  87.         return "Are you sure you want to leave?";
  88.     }        
  89. }
  90. function nopop() {
  91.     // nothing to return
  92. }
  93.  
  94. $(function() {
  95.     window.onbeforeunload = pop;
  96.     $(".panel").click(function() {
  97.         window.onbeforeunload = nopop;
  98.     });
  99. });
  100. </script>
  101.  
  102. <script>
  103. $(function() {    
  104.     $(".panel").click(function() {
  105.         window.open($(this).data("href"));
  106.         //setTimeout(function(){
  107.          //   window.location.href = "http://bing.com";            
  108.         //},500);
  109.     });    
  110. });    
  111. </script>
  112. </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement