How do I get IE9 to use standards compliant mode when developing on localhost?
Asked Answered
S

4

19

According to MSDN, all I need to force standards compliant mode is to include the HTML 5 doctype:

http://msdn.microsoft.com/en-us/library/gg699338%28v=vs.85%29.aspx

And it works when the markup is served remotely. The problem is when I take identical markup and serve it up from an apache server running locally. IE9 defaults to quirks mode, and the compatibility view button goes away.

I do a lot of development locally, and it defeats the purpose if I can only test my code in IE when it's served remotely. Thanks in advance.

Strictly answered 18/5, 2011 at 18:27 Comment(2)
Perhaps not the ideal fix... but if you run a web server locally (rather than directly accessing the file), then do you encounter the same issue?Tempting
I am serving the page from an apache server locally.Strictly
T
10

Try adding this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

At the top of your page. I'm not sure if that will work locally if the other you tried didn't... but it's worth a go.

Tempting answered 18/5, 2011 at 18:55 Comment(6)
Good suggestion, as I didn't even think to try older doctypes. Turns out they still don't work. I tried HTML 4.01 strict and XHTML 1.1 strict with the xmlns attribute on the html tag.Strictly
That is strange. Hmm... How are you telling if IE is in quirks mode? According to: msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx "When configured to load intranet pages in Compatibility View, Internet Explorer makes an exception for pages loaded using the localhost address or a loopback address. Pages loaded using one of these techniques are displayed in standards mode when the <!doctype> directive specifies a standards-based document type.". Could it be that it's disabling to option to go into compatibility mode for the local machine because it is already IN that mode?Tempting
I would test this out myself, but I'm not using a windows machine - sorry!Tempting
I am testing the page both locally and remotely. Some CSS3 stuff refuses to render from the local server only. I can't tell if it's in quirks mode, ie6 standards mode, ie7 standards mode, or ie8 standards mode, but I am certain it is not in ie9 standards mode.Strictly
After some further digging... I think this MIGHT help: blogs.msdn.com/b/ie/archive/2010/10/19/…Tempting
Good God that worked. It turns out it was using IE7 standards mode to render the page. Not sure why it defaulted to that considering the doctype and how the page claims the default is IE9 standards. This is actually insanely useful since it lets you switch between all of the different IE rendering modes. Feels like gaining a new super power.Strictly
D
32

Use <!DOCTYPE html> and add
<meta http-equiv="X-UA-Compatible" content="IE=9"> to the <head> section of your HTML page. It will force Internet Explorer to use IE standards mode.

Dasheen answered 30/12, 2011 at 14:32 Comment(5)
I used <meta http-equiv="X-UA-Compatible" content="IE=8"> to force my IE8 rendering. Thanks!Leslee
@Dasheen shouldn't it read content="IE=9" not value="IE=9" ??Doncaster
Yes it should be content. Thanks regardless, saved me a massive headache.Claus
You can use IE=Edge too, but make sure that you declare it after stylesheets or the rule may simply be ignored.Boldt
IE=Edge failed for me. thanks for this post, i was pulling my hair out.Speight
T
10

Try adding this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

At the top of your page. I'm not sure if that will work locally if the other you tried didn't... but it's worth a go.

Tempting answered 18/5, 2011 at 18:55 Comment(6)
Good suggestion, as I didn't even think to try older doctypes. Turns out they still don't work. I tried HTML 4.01 strict and XHTML 1.1 strict with the xmlns attribute on the html tag.Strictly
That is strange. Hmm... How are you telling if IE is in quirks mode? According to: msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx "When configured to load intranet pages in Compatibility View, Internet Explorer makes an exception for pages loaded using the localhost address or a loopback address. Pages loaded using one of these techniques are displayed in standards mode when the <!doctype> directive specifies a standards-based document type.". Could it be that it's disabling to option to go into compatibility mode for the local machine because it is already IN that mode?Tempting
I would test this out myself, but I'm not using a windows machine - sorry!Tempting
I am testing the page both locally and remotely. Some CSS3 stuff refuses to render from the local server only. I can't tell if it's in quirks mode, ie6 standards mode, ie7 standards mode, or ie8 standards mode, but I am certain it is not in ie9 standards mode.Strictly
After some further digging... I think this MIGHT help: blogs.msdn.com/b/ie/archive/2010/10/19/…Tempting
Good God that worked. It turns out it was using IE7 standards mode to render the page. Not sure why it defaulted to that considering the doctype and how the page claims the default is IE9 standards. This is actually insanely useful since it lets you switch between all of the different IE rendering modes. Feels like gaining a new super power.Strictly
V
4

I had this same problem. I had the HTML5 doctype on my aspx file, but it still rendered in IE7 mode. I fixed it without setting HTML4.01 Strict, and without meta http-equiv.

My problem was that I had an ASP tag, then the doctype in a separate line. IE9 wants the doctype to be on line 1 and nowhere else.

So if you have this:

<%
' some asp code
%>
<!DOCTYPE html>
<!-- rest of file -->

Consider changing it to this:

<%
' some asp code
%><!DOCTYPE html>
<!-- rest of file -->

This worked for me even with @Import statements before the initial asp block:

<%@ Import Namespace="System.Text.RegularExpressions" %>
<%
' some asp code
%><!DOCTYPE html>
<!-- rest of file -->
Vespiary answered 10/1, 2012 at 0:13 Comment(0)
C
3

See the "IE Windows special: the xml prolog" section in this document:

http://www.quirksmode.org/css/quirksmode.html

Anything before the DOCTYPE will cause it to switch to Quirks mode

Clobber answered 26/3, 2012 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.