简体   繁体   中英

Why does this JQuery Dialog Box appears again and again?

I am using Blogspot and My code is as follows:

//JQuery Code above <head> tag:
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

  <script>
  $(document).ready(function() {

      $("#dialog").dialog({ autoOpen: false });
      $("#dialog").dialog({ modal: true });
      $("#dialog").dialog({ position: 'center' });
      $("#dialog").dialog({ resizable: false });
      $("#dialog").dialog({ draggable: false });
      $("#dialog").dialog({ width: 280 });
      //$("#dialog").dialog({ height: 530 });
      //$("#dialog").dialog({ closeText: 'hide' });
      //$("#dialog").dialog({ closeOnEscape: true });
      //$("#dialog").dialog({ hide: 'slide' });
      //$("#dialog").dialog({ show: 'slide' });
      $("#dialog").dialog({ title: 'Help!' });

      /*$("#dialog").dialog({ buttons: [{
        text: "Close",
        click: function() { $(this).dialog("close"); }
      }] });*/

      $("#dialog").dialog();

      setTimeout(function(){
          $("#dialog").dialog("open");
      }, 30000);

  });
  </script>

//html code above </body>
<div id="dialog" title="Dialog Title">
<br>
<span style="text-align:center; font-weight:bolder;font-size:15px; display:block">Make this Hindi Site Popular. <br>
Please Share.</span>
<br>
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_linkedin"></a>
<a class="addthis_button_preferred_5"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=kuldeep06march"></script>
<!-- AddThis Button END -->
<br>
</div>

I have set timeout 30000 ms in setTimeout JS Function so after 30 seconds, a dialog box appears and asks for "Sharing". The problem is that after closing the Dialog Box, it appears again and again. See the live working code at "http://www.bccfalna.com"

How Can I solve this problem?

$("#dialog").dialog({ autoOpen: false,
modal: true,
position: 'center',
resizable: false,
draggable: false,
width: 280,
height: 530 ,
closeText: 'hide',
closeOnEscape: true,
hide: 'slide',
show: 'slide',
title: 'Help!' }).dialog();

and

 var timeoutId = setTimeout(function(){
      $("#dialog").dialog("open");
      clearTimeout(timeoutId)
  }, 30000);

Try this.

Well, in the link you provided you have the code snippet above wrapped in:

$window.scroll(function() {

Which means every time the user scrolls, you are creating a new timeout. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM