简体   繁体   中英

JavaScript setTimeout() in Chrome console

Why setTimeout doesn't work from Chrome console on some pages or what am I doing wrong?

setTimeout(function(){console.log('a');},3000);

output:

<- 6425

Example page: http://olx.pl


EDIT: Seems that on some pages console.log() is being overridden ... as it's site specific problem, this question should be deleted. But can't do that, as it has answers.

It does work. The catch is you may not be waiting enough.

 console.log(setTimeout(() => console.log('a'), 1000)); 

That number you get is the timeoutId . Anytime you call setTimeout or setInterval it returns a numeric ID which you can then pass to clearTimeout() or clearInterval() to abort it before it runs.

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