简体   繁体   中英

Timer loop never runs

All, I apologize for the simplicity of this question in advance, I'm new to programming. I have two functions, each prompts a url to load. I would like to use a timer loop to have these two functions run once every 30 seconds, and then repeat the loop. In the code below, the URL loads once, but never initializes the second URL. Thank you very much for assisting me with this question!

function initializeViz1() {
      var placeholderDiv = document.getElementById("tableauViz1");

      var url1 = "https://public.tableausoftware.com/views/SCADA_SERVER_DASHBOARD/Dashboard1?:embed=y&:display_count=no";

      var options = {
          width: 2000,
          height: 1200,
          hideTabs: true,
          hideToolbar: false,
          onFirstInteractive: function () {
              workbook = viz.getWorkbook();
              activeSheet = workbook.getActiveSheet();
          }
      };
      viz = new tableauSoftware.Viz(placeholderDiv, url1, options);
  }

  function initializeViz() {
      var placeholderDiv = document.getElementById("tableauViz");
      var url2 = "https://public.tableausoftware.com/views/Book1_1719/Sheet1?%3AshowVizHome=no#1";
      var options = {
          width: 2000,
          height: 1200,
          hideTabs: true,
          hideToolbar: false,
          onFirstInteractive: function () {
              workbook = viz.getWorkbook();
              activeSheet = workbook.getActiveSheet();
          }
      };
      viz = new tableauSoftware.Viz(placeholderDiv, url2, options);
  }


  var counter = 0;
  var i = setInterval(function () {
      // do your thing
      if (counter === 0) {
          $(initializeViz);
      } else if (counter === 1) {
          $(initializeViz1);
      }
      counter++;
      if (counter === 2) {
          clearInterval(i);
      }
  }, 15000);

You can use setTimeout() like this

function testFunction(){
    //do your thing

    setTimeout(testFunction, 30000);
}

testFunction();

Related post here: Call a javascript function every 5 seconds continuously

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