JavaScript JavaScript Basics Storing and Tracking Information with Variables Capturing Visitor Input

Jesse Dispoto
Jesse Dispoto
Front End Web Development Techdegree Graduate 14,280 Points

Why is the prompt loading before the html on the page loads?

The source.js file is placed on the bottom of the html document. Why is the prompt displaying before the page loads? Shouldn't it prompt after the page loads, according to the order in the html?

2 Answers

Jamin Pratt
Jamin Pratt
Full Stack JavaScript Techdegree Student 1,920 Points

on Google

// Once the browser has received the document (html file) it reads it. The web browser looks at the entire HTML document and looks for any css, javascript and images that are referenced by the page. If resources are found in the HTML the web browser then requests each of those resource files from the webserver. //

"The web browser looks at the entire HTML document"

It would seem that a browser looks at the entirety of the document and elements before loading. so when the prompt command comes it gets stuck and has to collect it first. if you want it to wait you would need to make it only prompt after the page is loaded... there are a few ways on the internet

Ismayil Aliyev
Ismayil Aliyev
18,529 Points

It also depends on the browser. On Edge it also shows the HTML code while running Prompt and Alert whereas on Chrome HTML is seen only after the execution of the JS.