简体   繁体   中英

How to run this code snippet from console

I have a js function(timer to reload the webpage) running on a website and I want to know is there any way to access and modify variables in this function so that website can reload right now.

I tried to access variables using following in the console

window.secondsLeft=0

But nothing happened. If I tried to access any other variable I got .

<script type="text/javascript">
var end_time = moment().add(265.96296960866664, 'minutes').toDate();
var totalSeconds = 15957.778176519998;
$('#clock').countdown(end_time).on('update.countdown', function(event) {
   var format = '%D Days %H Hr : %M min : %S sec ';
   var secondsLeft = (new Date(end_time).getTime() - parseInt(event.timeStamp))/(1000);
   var percentage = 100 - (secondsLeft/parseFloat(totalSeconds))*100;
   if (secondsLeft <= 60 && secondsLeft >= 59)   {
       toastr.info('Starting!.', 'Info', {timeOut: 5000});
   } 
  else if (secondsLeft <= 0)    {
       toastr.clear();
   }
   $(this).html(event.strftime(format));
   })
   .on('finish.countdown', function(event) {
   document.location.reload(true);
   });
</script>

Is there any way to set secondsLeft = 0 ?

The only way you could change a local variable in the console is to set a breakpoint in the code that has access to that variable, and once the breakpoint is hit enter your command in the console. Other than with breakpoints, any commands are going to run in a global scope, and don't have access to local variables.

您可以尝试覆盖$('#clock')的事件侦听器

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