Adding a doctype w/o killing off current functionality
I had to repurpose some old code for a rush job, and while that code QA's fine it turns out not to have a doctype declared. When 开发者_如何学运维I add a doctype, it breaks the design in IE. Ideally, I would be able to declare whatever doctype is assumed when none exists, but don't know if that's possible. Is there a way I can declare a doctype without changing the behavior created by a page w/o any doctype declared?
Without a doctype, IE will show the page in quirks mode. To keep IE in quirks mode with a doctype, you can add a comment (<!-- -->
) before the doctype.
Edit: if it's just IE6 causing problems, the XML prolog (<?xml version="1.0" encoding="utf-8"?>
) will keep it in quirks mode.
Edit 2: there's actually lots of doctypes that will keep IE in quirks mode. You should be able to find one you can validate against.
I have been in a similar situation before. My recommendation would be to run your HTML through an HTML validation tool while you are doing this. My favorite is this one:
http://validator.w3.org/
There is also a firefox plugin if you need to authenticate or have some sort of other mechanism to access the page (and cannot have that site access your site directly).
If the 'functionality' you describe is actually one of the many IE 'undocumented features' (bugs) you are not going to be able to make your HTML standards compliant AND have it continue to function. It is likely that you have a number of non standards compliant pieces of code, and the IE-specific error handling is what is making your page function at all. Different browsers handle error conditions differently (since by definitional, error conditions are outside the scope of a document type).
To reiterate, try and make your HTML pass some sort of validation, then worry about adding the functionality back it. My experience has shown me that error conditions usually result in these sort of problems you are describing.
That's the #1 rule I have encountered with web development. The page needs to validate for some specific doctype.
Good luck!
-Brian J. Stinar-
It's impossible because it would change quirks mode to standards mode ( assuming you use something like XHTML Transitional, HTML 4 Strict or HTML 5 ) and there are quite a few discrepancies especially with IE. You'd have to fix things around or hire someone else to.
精彩评论