# Load Javascript Alert while the page is loading

**URL:** <https://www.phphelp.com/t/load-javascript-alert-while-the-page-is-loading/35331>\
**Category:** Javascript & Ajax\
**Created:** [March 8, 2023, 1:52am UTC](https://www.phphelp.com/t/load-javascript-alert-while-the-page-is-loading/35331 "2023-03-08T01:52:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bondikho](https://www.phphelp.com/letter_avatar_proxy/v4/letter/b/57b2e6/32.png) [@bondikho](https://www.phphelp.com/u/bondikho)\
**Post date:** [March 8, 2023, 1:52am UTC](https://www.phphelp.com/t/load-javascript-alert-while-the-page-is-loading/35331/1 "2023-03-08T01:52:50Z")

</div>

0

Im wondering if its possible to load a JavaScript alert before the content while the page is loading

Whatever I try to do the alert fires and the page doesn’t load until the alert is closed

> ```auto
> <script>
> alert('But wait, there\'s more...');
> </script>
> 
> ```

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [March 9, 2023, 2:41pm UTC](https://www.phphelp.com/t/load-javascript-alert-while-the-page-is-loading/35331/2 "2023-03-09T14:41:41Z")

</div>

Well, you can use a page-listener to do this. Something like this should work:

```auto
<head>
<script type="text/javascript">
document.onreadystatechange = function() {
    if(document.readyState=='loaded' || document.readyState=='complete')
        alert('But wait, there\'s more...');
}
</script>
</head>

```

Or, if you are using Bootstrap on your site, you could use a modal pop-out which would work too.  
If you want to do that, here is a site that shows how to do that: [Bootstrap-Modal on page-load](https://www.tutorialrepublic.com/faq/how-to-launch-bootstrap-modal-on-page-load.php)
