I have an html page that open a popup window when the page loads.
I need to set the popup only when the page open first time. I think session or cookie is to be set.
<script> !window.jQuery && document.write('<script src="fancybox/jquery-1.4.3.min.js"><\/script>'); </script> <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.pack.js"></script> <script type="text/javascript"> $(document).ready(function() { $("a#example1").fancybox(); $("a#example1").trigger('click'); }); </script> <link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.4.css" media="screen" /> </head> <body> <a id="example1" href="images/pic.jpg"></a> </body>
jQuery is a JavaScript library and JavaScript is a Client Side language and hence directly it is not possible to set Session variable in jQuery.
To set the Session value you need to make ajax call to ActionResult and pass the id and text as parameter and set the session inside the ActionResult and redirect to the specified page to do the rest of functionality. // Set Session values. Then in the report controller get the Session Values and do rest of task.
To use session data ,you don't need jquery you can use setItem ,getItem and removeItem to deal with the session data which is stored as a json object and accessible via key.
jQuery is a Javascript library, which is a client-side language. Setting a session variable using a client-side function is not possible. So we make an Ajax Call using a jQuery to pass the variable value to the controller and set a session variable. Now let get started by creating a model Country as shown below.
Use localStorage to store the fact that you opened the page :
$(document).ready(function() { var yetVisited = localStorage['visited']; if (!yetVisited) { // open popup localStorage['visited'] = "yes"; } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With