Download Javascript warnings before showing page

On my mobile phone in safari. If I go to my default page, which has an alert("Hello") in the onload body event, a warning will be displayed with my default page fully visible in the background. If I then go to another site, for example, bbc.co.uk, and then enter my address for my default page in the address bar, a warning will be displayed with BBC content in the background, like a reminder loaded before the page is loaded.

How do I show a message only after the entire page is visible. I read that window.onload waits until everything is loaded before the warning is triggered, but I have to get something wrong, because the behavior does not change. I also tried:

 $(document).ready(function () { window.onload= alert('Test'); }); 

and

 <meta http-equiv="Pragma" content="no-cache"/> 

if it has anything to do with cache, but I don't think this is a problem. Any ideas?

thanks

+6
source share
4 answers
 $(window).load(function() { alert('Test'); }); 
+2
source

You pass a link to the window.onload function, not the actual call.

to try

 window.onload = function(){ alert('test'); } 
+7
source

If you want to display the alrert window or use window.onload, it makes no sense to use both, here is the code that will work fine

window.onload (which is implemented even in older browsers), which starts when the whole page loads

  window.onload = function(){ alert('test'); } 

jQuery provides document.ready , which abstracts them, and fires as soon as the DOM page is ready

 $(document).ready(function () { alert('Test'); }); 

Check the answer: window.onload vs $ (document) .ready ()

window.onload is a built-in Javascript event, but since its implementation had subtle quirks in browsers (FF / IE6 / IE8 / Opera), jQuery provides a document.ready that abstracts them and fires as soon as the DOM page is ready (no images wait etc.).

document.ready is a jQuery function wrapping and ensuring consistency with the following events:

  • document.ondomcontentready / document.ondomcontentloaded - a new event that is fired when a DOM document is loaded (which may take some time before loading images, etc.); again, is slightly different in IE and the rest of the world.
  • and window.onload (which is implemented even in older browsers), which starts when the entire page loads (images, styles, etc.).
+3
source

 <!DOCTYPE html> <html> <body onload="show_popup()"> <script> function show_popup() { alert("Popup shows"); } </script> </body> </html> 
-1
source

Source: https://habr.com/ru/post/924623/


All Articles