aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes When is Document object created for an HTML page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "When is Document object created for an HTML page" Watch "When is Document object created for an HTML page" New topic
Author

When is Document object created for an HTML page

Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
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.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Spencer Killen
Greenhorn

Joined: Nov 08, 2013
Posts: 3
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When is Document object created for an HTML page