• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When is Document object created for an HTML page

 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to understand how browser loads and display the pages and as per research below are my finding and questions.

What I learnt:

Browser tokenize the content and send it to the parser.

Parser creates the document tree by reading the input sent by the tokenizer and it blocks the parsing if it has to download the Javascript and execute the script and then continue parsing.

Question:

If my javascript contains document.write(),Can I safely assume that before browser starts parsing the page,it will create the document object as I am wondering how the document is available before even the DOM is constructed?

Thanks in advance.
 
Spencer Killen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope 'document.write() can be called even after the page is full loaded, you can prove this by executing it in the console F12 in google chrome, I believe the browser will read everything in the head content and parse it and then start reading from the body parsing/displaying/executing it while it comes
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spencer Killen wrote:Nope 'document.write() can be called even after the page is full loaded

While it can be called after the DOM has been built, it replaces the previous document with the passed value making it pretty useless in most cases.

To answer the OP, the DOM is an aspect of the document object. There's no reason the object cannot be available while its DOM is being built.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic