在IE9中使用html5怪癖模式 [英] Using html5 quirks mode in IE9

查看:132
本文介绍了在IE9中使用html5怪癖模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用JavaScript动态创建的表单,并使用< script> 标记添加到另一个网站中。



其他网站使用的文档类型为<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Transitional // EN> 它使用怪癖模式。

通过考虑这一点,我已经构建了我的表单,并且Chrome,Firefox和IE 10中的所有内容都按预期工作。但是,当我在IE 9中测试它时,此前,表单根本不显示。当我打开开发工具时,我可以看到IE 10使用新的怪异模式,但IE 9和更早版本使用IE5怪异模式。

我想知道当使用IE 9及更早版本时,是否可以使用新的怪异模式显示此页面。如果这是不可能的,我想强制使用标准模式,但只能在使用IE 9或更早的版本时使用,并且对其他浏览器保持怪癖。



我无法使用HTML5的文档类型,因为他们的网站是用怪癖模式而不是标准构建的,当我使用这种文档类型时,它们的设计都被破坏了。

解决方案

加载页面后,您无法更改模式。而且你不能通过编程来改变它。强制页面进入怪癖模式的 only 方法是在没有有效的文档类型或HTML中存在严重错误的情况下加载它。

如果你有一个文档类型,但你的页面仍然以怪癖模式加载,那么这意味着你的HTML中存在严重的错误。这会给你更大的问题,而不仅仅是在怪癖模式。你一定要修复这些错误。如果您确实想要进入怪异模式,请删除文档类型,但您应该尽量不要使HTML代码非常糟糕,即使使用文档类型也会触发怪异模式!



您可以使用 W3C验证器验证您的HTML以查找这些错误。



在IE10的两种不同怪癖模式之间切换页面时,最简单的答案就是不能这样做。



对不起。



然而,说实话,这可能是最好的。无论如何,使用怪癖模式是一个完整的灾难。它不只是改变布局模式;它也关闭了浏览器的大部分功能(比如自1998年以来发明的几乎所有功能)。

但现在有个好消息:



幸运的是,从Quirks模式切换比您想象的要容易得多。



主布局问题box模型)可以通过将以下内容添加到CSS的顶部来修复:

  * {box-sizing:border-box ;} 

这是将盒子模型设置为怪癖模式样式布局的符合标准的方法。大多数由怪癖模式转换为标准模式导致的布局问题可以通过这种简单的CSS风格解决。



还有其他的怪癖,但它们相对较小一旦你解决了主要问题,不应该太难处理。其中许多实际上并不是怪癖模式问题,而是旧版IE中的错误,原来的编码器可能不得不绕过他的方式。无论如何,即使您坚持使用怪癖模式,也无法保证这些版本在未来的版本中仍能继续保持相同的效果,所以无论如何,您最好现在修复它们。




所以,总结一下:


  1. 修复您的页面,使其在标准模式下加载。有效的doctype和有效的HTML。

  2. 使用 box-sizing 来减轻交换机造成的主布局gremlins。 b $ b
  3. 手动修复剩余的布局问题。

这听起来确实少了很多工作。诚实。


I've created a form that is dynamically created with JavaScript and is added in another website using the <script> tag.

The doctype used by this other website is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> which uses the quirks mode.

I've built my form by taking this in consideration and everything is working as expected in Chrome, Firefox and IE 10. However, when I test it in IE 9 and earlier, the form is not displayed at all. When I open the developper tools, I can see that IE 10 uses the new quirks mode but IE 9 and earlier uses the IE5 Quirks mode.

I was wondering if the new quirks mode can be used to display this page when using IE 9 and earlier. If this is not possible, I would like to force standard mode but only when using IE 9 or earlier and keep using quirks for every other browser.

I can't use the html5 doctype since their website is built with quirks mode instead of standards and their design is all broken when I use this doctype.

解决方案

You cannot change the mode once the page is loaded. And you cannot change it programmatically. The only way to force a page into quirks mode is to load it without a valid doctype or with serious bugs in the HTML.

If you have a doctype, but your page is still loading in quirks mode, then it means that you have serious bugs in your HTML. This will give you bigger problems than just being in quirks mode. You should definitely fix those bugs. If you really want to be in quirks mode, drop the doctype, but you should really try not to have HTML code that is so bad it triggers quirks mode even with a doctype!

You can validate your HTML to find those bugs by using the W3C validator.

In terms of switching your page at runtime between IE10's two different quirks modes, the simple answer is that you can't do that.

Sorry about that.

However, to be honest, it's probably for the best. Using quirks mode is be a complete disaster anyway. It doesn't just change the layout mode; it also switches off most of the browser's features (ie pretty much everything invented since 1998).

But now for the good news:

Luckily, switching away from Quirks mode is a lot easier than you think.

The main layout issue (the different box model) can be fixed by adding the following to the top of your CSS:

*{box-sizing:border-box;}

This is the standards-compliant way to set the box model to the quirks-mode style layout. Most of the broken layout problems cause by switching from quirks mode to standards mode can be resolved with this simple CSS style.

There are other quirks, but they're relatively minor and shouldn't be too hard to deal with once you've fixed the main issue. A lot of them are actually not quirks mode issues, but bugs in older IE versions that the original coder may have had to hack his way around. There's no guarantee that these will continue working the same in future versions anyway, even if you do stick to quirks mode, so you would be best off fixing them now anyway.

So, to summarise:

  1. Fix your page so it loads in standards mode. Valid doctype and valid HTML.
  2. Use box-sizing to mitigate the main layout gremlins caused by the switch.
  3. Fix the remaining layout issues manually.

It's really a lot less work than it sounds. Honest.

这篇关于在IE9中使用html5怪癖模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆