Jquery script with cookies
I have a script that open up a fancybox form once browser closed/refreshed/back is pressed (onbeforeunload).
Now I'm trying to make the fancybox pop up only once so i installed the cookies plugin and started to play with it but it doesn't seems to work , maybe you can help me here
- <html dir="ltr">
- <head>
- <script type="text/javascript" src="jquery14.js"></script>
- <script type="text/javascript" src="jquery.cookie.js"></script>
- <script src="fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
- <link rel="stylesheet" href="fancybox/jquery.fancybox-1.3.1.css" type="text/css" media="screen"/>
- <script type="text/javascript">
- $.cookie('appeal'); // get cookie
- $.cookie('appeal', 'the_value'); // set cookie
- function PopIt()
- {
- if ($.cookie('appeal') == null)
- {
- $.cookie('appeal', 'cookieValue', { expires: 7 });
- $("a#trigger").trigger('click');
- window.onbeforeunload = UnPopIt;
- return "Before you leave:\nPlease take a few seconds to answer 2 questions\nso we can better assist you and others in the future. \nThanks!";
- }
- else { }
- }
- function UnPopIt() { /* nothing to return */ }
-
- $(document).ready(function() {
- window.onbeforeunload = PopIt;
-
- $("a#trigger").fancybox({
- 'hideOnContentClick': false,
- 'showCloseButton': true
- });
-
- $("a[id!=trigger]").click(function(){ window.onbeforeunload = UnPopIt; });
- });
- </script>
- </head>
- <body>
- <p>This page is an exit-pop</p>
- <div style="display: none;">
- <a id="trigger" href="#popup"> </a>
- <div id="popup" style="width: 250px; height: 400px;">
- My Form is here
- </div>
- </body>
- </html>