In below, When i click on button call the jquery click event,It will first shows the alerts upto this it works properly, In this i have call two functions(i.e. reload() and popup()) when i click on button it gives alerts and after that it execute popup() function and reload() function at a time. My query is i want to execute first reload function(it reload only once) then execute popup function means when i click on button first reload the page only once and then show me my popup.
<script>
  $(document).ready(function()
              { 
                  $('.button').click(function()
                  {
                      var href = $(this).val();
                      alert(href);
                      $.session.set("linkurl",href);
                      alert($.session.get('linkurl'));
                      //window.location.reload();
                        function reload()
                        {
                            if(document.URL.indexOf("#")==-1)
                            {
                            // Set the URL to whatever it was plus "#".
                            url = document.URL+"#";
                            location = "#";
                            //Reload the page
                            location.reload(true);
                            return true;
                            }
                        }
                        function popup()
                        {
                            document.getElementById('light').style.display='block';
                            document.getElementById('fade').style.display='block';
                        }
                        $.when( reload() ).done(function() {
                            popup();
                        });
                  }); 
              });
</script>
<button  class="button"  value="<?php echo $value['3']; ?>" style="background-color:#ff8c21;">Buy Now</button>
 
     
     
     
     
    