1

I used to use alert to halt the rendering. However, recently I noticed that the alert can be automatically killed in some cases.

So I am thinking, is there any way to stop the HTML rendering?

A widely used way is to use a breakpoint but there is any way that I could put something in the source code to do so? or to invoke a pause in the console?

AGamePlayer
  • 7,404
  • 19
  • 62
  • 119

3 Answers3

0

No it's not possible in a clean way. The only Javascript blocking functions are alert, confirm and prompt. You can force a breakpoint with the debugger keyword, but it will only work if the DevTools are opened.

Guerric P
  • 30,447
  • 6
  • 48
  • 86
0

This would kind of work:

let start = Date.now()
let defertime = 10*1000 // 10 second deferring

while (Date.now() - start < defertime) {
  // do nothing but block JS and page rendering
}

console.log('continuing')
connexo
  • 53,704
  • 14
  • 91
  • 128
  • Theoretically works, but it's a busy wait which will eat the entire UI thread and prevent user interaction, so I strongly advise against using it! – Duncan Thacker Jan 28 '19 at 13:12
-3

You could “sleep” the page for a set amount of time by doing this: What is the JavaScript version of sleep()?

JasonR
  • 401
  • 3
  • 11