Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html5shiv requires explicit "<body>" tag #100

Open
davidrl opened this issue Apr 28, 2013 · 2 comments
Open

html5shiv requires explicit "<body>" tag #100

davidrl opened this issue Apr 28, 2013 · 2 comments

Comments

@davidrl
Copy link

davidrl commented Apr 28, 2013

According to the spec, the <body> tag is optional. However it seems that it is necessary to explicitly include it for html5shiv to work.

For example this works:

<!doctype html>
<title>Example</title>
<style>header {display: block;}</style>
<script src="html5shiv.js"></script>
<body>
<header>Example</header>

But if you take out the <body> tag then the page will be blank.

Not a big deal, but maybe could be mentioned in the "Known issues" section.

@stijnherreman
Copy link

It is a big deal IMO, this just cost me quite some time to find out why we were getting a blank screen on IE8.

This works:

<!doctype html>
<title>jquery-test.html</title>
<script src="html5shiv.js"></script>
<body>
    <header>
        <hr>
    </header>
    <script src="jquery-1.10.2.js"></script>
</body>

This crashes with an obscure jQuery error:

<!doctype html>
<title>jquery-test.html</title>
<script src="html5shiv.js"></script>
<header>
    <hr>
</header>
<script src="jquery-1.10.2.js"></script>

Unknown runtime error jquery-1.10.2.js, line 3489 character 3
line 3489: div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";

@aFarkas
Copy link
Owner

aFarkas commented Nov 21, 2013

I'm not fully convinced, that we should document every edge case. html5shiv simply adds the capability of using the new elements, it does not implement the HTML -> DOM parsing algorythm. This should be clear. The browser including IE8 simply auto inserts the body on the first element, which has to be in the body. There are only some bugs in IE, that unknown elements (like HTML5 ones), div and form elements do not trigger this insert. This means the following code works again:

<!doctype html>
<title>jquery-test.html</title>
<script src="html5shiv.js"></script>
<hr />
<header>
</header>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Or even a textnode is good enough for this:

<!doctype html>
<title>jquery-test.html</title>
<script src="html5shiv.js"></script>
<hr />
<header>
</header>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

This said: Especially, if you work with a CMS and you are using multiple different templates, it is always bad to omit html, head and body. Because you do not have full control, where it is inserted (although modern browsers are doing it consistent way.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants