Document Modes & Noscript in JavaScript: Definition & Use

Instructor: Alexis Kypridemos

Alexis is a technical writer for an IT company and has worked in publishing as a writer, editor and web designer. He has a BA in Communication.

In this lesson, we'll demonstrate through code examples how to view the document mode of the Internet Explorer web browser using JavaScript. Also, we'll demonstrate how to use the noscript element for when the browser does not support JavaScript.

The Document Mode

The document mode is a property of the document object. The document mode returns a numeric value which indicates in which mode the Internet Explorer web browser is currently viewing the document (web page). If a web browser other than Internet Explorer is used to view the document, the document mode property returns the value ''undefined''.

The document object, as discussed in lessons about the DOM, Document Object Model, refers to how web browsers load and interpret an HTML or XML document as an object with specific properties. One of these properties is the document mode, but only applies to the Internet Explorer browser, as mentioned above. If the document is actually being viewed in Internet Explorer, the possible values the document mode property can take are:

  • 5
  • 7
  • 8
  • 9
  • 10
  • 11

These values correspond to the Internet Explorer mode being used to view the document. In turn, the mode number corresponds to an Internet Explorer version number. A very important point to keep in mind is that document modes were deprecated as of Internet Explorer version 11.

Modes vs. Versions

The distinction between version and mode essentially means that a version of Internet Explorer, for example version 8, can interpret a document as that version, but also as a previous version, for instance version 5. ''Mode'' refers to which version Internet Explorer is currently interpreting the document as.

Mode History

The reason certain versions of Internet Explorer may interpret a document as another version, or mode, is that with IE version 8, Microsoft made some significant improvements to the browser. Having made these changes, they then realized that many web pages may have been created in such a way so as to cater to the previous versions' shortcomings. Having addressed these shortcomings in version 8, there was a strong possibility that that version would not be able to correctly interpret these pages.

To resolve the issue, Microsoft included the capability in version 8 of interpreting a document as if it were an older version, such as 7 or 5.

The primary factor that determines what mode Internet Explorer will use to interpret the document is the presence of a <!DOCTYPE>. If the document does not specify a <!DOCTYPE>, the browser will interpret the document in version 5 mode.

Other factors that determine which document mode IE will use include the presence of a meta tag in the <head> element which forces IE to use a certain mode, and settings on the browser and computer itself, like the Compatibility View settings and Group Policy settings.

The <noscript> Element

The <noscript> element is used to display a plain text message in the web browser window when the browser does not support JavaScript, as a way of explaining to the user why the web page content is not displaying correctly.

Let's see a code example demonstrating how to use both the <noscript> tag and the document mode property. As always, feel free to copy the code and paste it into an online HTML or JavaScript editor, or save it as an .html file on your computer and load it in a web browser, to see it in action.

<!DOCTYPE html>
 var mode = document.documentMode;
 if (mode == undefined){
  alert("You are using a browser other than Internet Explorer.");
 } else if (mode != undefined){
  alert("This page is being rendered using Internet Explorer mode " + mode);
<noscript>JavaScript is not enabled on your web browser. Please enable JavaScript to view the full content of this web page.</noscript>

In the above example, we have an HTML document which is empty apart from the <script> element, which contains the JavaScript code.

We create the variable mode, and store in it the value of the documentMode property with the first line:

var mode = document.documentMode;

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account