---
title: "Loader before loading an HTML file through JavaScript"  
description: "Loader before loading an HTML file through JavaScript"  
author: "Anonymous User"  
published: 2021-07-19  
updated: 2021-07-19  
canonical: https://www.mindstick.com/forum/156514/loader-before-loading-an-html-file-through-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Loader before loading an HTML file through JavaScript

How to display a loading bar before the entire [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) is loaded through [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Ethan Karla

Loading bar can be achieve with the help of window load event. The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images.

Let's understand it with the help of an example :

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title>Asynchronous JavaScript </title>
    <script>
        window.onload = function () {
            // PAGE IS FULLY LOADED
            // FADE OUT YOUR OVERLAYING DIV
            var fadeTarget = document.getElementById('overlay');
            fadeTarget.style.opacity = 0.1;
        };
    </script>
</head>
<body align='center'>
    <div id='overlay'>
    <img src='loading.gif' alt='Loading' />
    Loading...
</div>
</body>
</html>
```

Hope this information has cleared your confusion.

Happy Coding!


---

Original Source: https://www.mindstick.com/forum/156514/loader-before-loading-an-html-file-through-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
