[英]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. 我有一个在网站上运行的js函数(用于重新加载网页的计时器),我想知道有什么方法可以访问和修改此函数中的变量,以便网站可以立即重新加载。
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 undefined . 如果尝试访问任何其他变量,则无法定义 。
<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 ? 有什么方法可以设置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')的事件侦听器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.