Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding support for elements in older browsers

From: HTML5: Structure, Syntax, and Semantics

Video: Adding support for elements in older browsers

In our last movie, we made sure that our new HTML5 structural elements would display properly, even if they didn't really understand what all the elements were. That's not entirely true. While this technique works in almost all browsers, older versions of Internet Explorer--and by this, I mean those prior to IE9--can stumble badly when introduced to elements that they're not familiar with, even if you instruct those elements to display as block level. Now prior to Internet Explorer 9, which now, by the way, handles all of the HTML5 elements beautifully, the browser would insert the element into the DOM as an empty node with no children.

Adding support for elements in older browsers

In our last movie, we made sure that our new HTML5 structural elements would display properly, even if they didn't really understand what all the elements were. That's not entirely true. While this technique works in almost all browsers, older versions of Internet Explorer--and by this, I mean those prior to IE9--can stumble badly when introduced to elements that they're not familiar with, even if you instruct those elements to display as block level. Now prior to Internet Explorer 9, which now, by the way, handles all of the HTML5 elements beautifully, the browser would insert the element into the DOM as an empty node with no children.

As you can imagine, this creates a glorious mess. Fortunately, the fix for this is pretty simple, and it's something you can do yourself, or you can take advantage of a pretty neat piece of code online that can do the job for you. So we're going to be working in the trails.htm file, which you can find in the 06_03 folder. And as I mentioned before, the fix is fairly simple. Now for earlier versions of Internet Explorer, if you use JavaScript to create the elements that you are going to use and you do that in the head of the document, then Internet Explorer will then recognize the elements and style them improperly, even if you don't use JavaScript to place the scripted elements on the page.

So again, pretty simple. I'm going to go right into the head of the document, and just after the link to my style sheet, I'm going to go ahead and open up a script tag. Then I'll go ahead and enclose the script tag. Now inside of this, all we have to do is some very simple JavaScript. So I'm going to start with a document, and I'm going to use the createElement method, and I'm just going to create an article. Now, I can just keep going here, creating as many of these elements as I want. I know I'm going to use sections, for example, so I can just come in and do document, createElement, and maybe we will do a section.

So for each one of these you want to use, you would just go ahead and create each one. So article, aside, nav, section, whatever you are wanting. Now that of course is going to get kind of tedious, and I really doubt you would want have to do it on every single page of your site. So one solution would be to go ahead and externalize the JavaScript in a document that you could use throughout the entire site, and even use over and over again through sites. Or you could just take advantage of the fact that somebody has already done this for you. The wonderfully talented Remy Sharp has created his HTML shim script to assist earlier versions of Internet Explorer and supporting these HTML5 elements.

Now you can read about the shim project at his blog, remysharp.com. If you go into his archives, look in the January of 2009--so this has been around for a while-- you'll find his article on the HTML5 enabling script. And he is talking about kind of how he's basing this work off some previous work and prior work. Well, the project that he started here soon kind of took on a life of its own, and currently the code is being hosted through Google Code. So let me show you where to find that. And if you go to code.google.com/p/ html5shim/, you'll land on this page, which is the project home for the html5shim.

Now here you can do a couple of different things one of the first and the easiest things is to do is what we're going to do, which is to simply copy and paste the example script into the head of your document. I am just going to go ahead right down here and find the conditional comment that's being used. So what we have here is we have a conditional comment that's saying if the browser is less than Internet Explorer 9, go ahead and link out to this site to the JavaScript and use that. So this is only used for browsers that are Internet Explorer, earlier than version 9.

So I'm going to copy that and go back in my code. Now coming back into my code, I can go ahead and get rid of this script and then simply replace it with this conditional comment that we've copied and pasted from the Google Code site. Now for most people, this should work, and if you look at a lot of examples of HTML5 sites out there, you're going to find this conditional comment sitting within the code. However, in certain projects or certain corporations, you're going to want to self-host this code or come up with your own solution.

Now I know this might not be feasible for every single corporation or every single instance; sometimes all of your code needs to be self-hosted, and sometimes you might not want rely on an external asset. Well, in those cases, one of the things you can do is go straight to the link itself, copy and paste the JavaScript, or modify it to suit your own needs. Now if you plan on doing that, be sure to go back to the Google Code page and read the code license. It has an MIT license. You want to make sure that whatever you're doing, if you're modifying this code or reusing it in some way, that you're in compliance with the existing license for the code.

Okay, so going back to our own page, I want to go ahead and save that, and of course, we were to preview this in one of the browsers that we've been using so far. We really would notice a difference, but however, for previewing it on an earlier browser, such as Internet Explorer 7 or Internet Explorer 8, we would now see all of our elements displaying the way that we wanted them to as block-level element. So we have helped to ensure that our page is going to work in older versions of Internet Explorer. Another thing that I really like about Remy's script is that when necessary, it is updated to fix bugs or support additional features, such as the printing of the new HTML5 elements, for example-- that was added fairly recently.

So there you have it. We've now have helped to ensure that our page is going to work in older versions of Internet Explorer.

Show transcript

This video is part of

Image for HTML5: Structure, Syntax, and Semantics
HTML5: Structure, Syntax, and Semantics

46 video lessons · 39010 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 20s
    1. Welcome
      48s
    2. Using the exercise files
      1m 32s
  2. 18m 41s
    1. A brief overview of HTML5
      3m 57s
    2. What's in the HTML5 specification?
      8m 17s
    3. Why do we need new structural elements?
      6m 27s
  3. 50m 33s
    1. Defining HTML5 documents
      5m 5s
    2. HTML5 syntax
      9m 14s
    3. The header element
      5m 22s
    4. The nav element
      4m 55s
    5. The section element
      4m 51s
    6. The article element
      4m 48s
    7. The aside element
      4m 13s
    8. The footer element
      4m 17s
    9. Content model overview
      7m 48s
  4. 35m 28s
    1. Understanding the outline algorithm
      3m 17s
    2. Creating document sections
      8m 25s
    3. Using headings properly
      9m 1s
    4. Using hgroup to override sectioning
      4m 17s
    5. Properly nesting structure
      7m 17s
    6. Sectioning roots
      3m 11s
  5. 58m 30s
    1. Organizing content
      4m 41s
    2. Planning document structure
      5m 47s
    3. Choosing the right structural element
      4m 43s
    4. Checking document outlines
      5m 27s
    5. Coding initial page structure
      5m 28s
    6. Using class and ID attributes
      5m 31s
    7. Structuring headers
      13m 13s
    8. Building navigation
      7m 1s
    9. Structuring footers
      6m 39s
  6. 1h 27m
    1. Working with figure and figcaption
      7m 12s
    2. Grouping content with asides
      3m 46s
    3. Using divs in HTML5
      5m 0s
    4. Working with lists in HTML5
      7m 10s
    5. The return of bold and italic
      5m 52s
    6. Citing works semantically
      6m 32s
    7. Using the address element
      5m 24s
    8. Using the small element
      4m 24s
    9. Using the mark element
      5m 16s
    10. Working with date and time
      11m 55s
    11. Creating block-level links
      8m 53s
    12. Understanding link relationships
      9m 28s
    13. Defining link relationships
      6m 23s
  7. 17m 22s
    1. Current browser support
      7m 38s
    2. Ensuring block-level display
      4m 3s
    3. Adding support for elements in older browsers
      5m 41s
  8. 3m 46s
    1. Additional Resources
      3m 46s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML5: Structure, Syntax, and Semantics.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.