-1

I am using javascript for page refresh. put a new button and I want this refresh canceled when I press the button.

how can I do it.

<script type="text/javascript">
       function waitfor() {
           window.location.reload();
       }
       setInterval("waitfor()", 10000);
   </script>
  • 1
    https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval – Teemu Jan 18 '21 at 18:54

3 Answers3

0

the setInterval function returns an ID, you can clear the interval using that ID:

<script type="text/javascript">
       function waitfor() {
           window.location.reload();
       }
       var intervalID = setInterval("waitfor()", 10000);
       var btn = document.getElementById("myButton");
       btn.addEventListener("click", function() {
           clearInterval(intervalID);
       });
   </script>
chack1172
  • 84
  • 1
  • 8
  • Thank you. The refresh script runs automatically when it enters the page. but the same button is doing in other operations, as I put it in the code, how will I do it then. – Erhan Şimşek Jan 18 '21 at 19:47
0

get the button and make event listener when making click on the button the function will run this function will use clearInterval() function to stop setInterval

<script type="text/javascript">
document.getElementById("stop").addEventListener("click", stopInterval);

function waitfor() {
    window.location.reload();
}
var timer = setInterval(waitfor, 2000);

function stopInterval() {
// To cancel an interval, pass the timer to clearInterval()
clearInterval(timer);
}
0

 $(document).ready(function () {
                       $("button").click(function () {
                                                   
                           $("td").remove();

                           const panorama = new google.maps.StreetViewPanorama(
                               document.getElementById("map2"),
                               {
                                   position: { lat: <%#Eval("Latitude").ToString().Replace(",",".") %> , lng: <%#Eval("Longtitude").ToString().Replace(",",".") %> },
                                   addressControlOptions: {
                                       position: google.maps.ControlPosition.BOTTOM_CENTER,
                                   },
                                   linksControl: true,
                                   panControl: true,
                                   enableCloseButton: true,
                                   
                               }
                           );
                          
                       });
                   });