• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

When is Document object created for an HTML page

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67641
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic