IE9,IE8,SVG,VML和doctypes [英] IE9, IE8, SVG, VML and doctypes

查看:96
本文介绍了IE9,IE8,SVG,VML和doctypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用ASP.NET Web应用程序绘制图形.在IE9和其他浏览器中,我正在使用SVG进行操作,并且效果很好.在IE8及以下版本中,我正在使用VML.我发现在IE8标准模式(不使用兼容性视图)下,IE8根本不显示VML.

I'm working on drawing shapes in my ASP.NET web app. In IE9 and other browsers, I'm doing it with SVG, and it's working great. In IE8 and below, I'm using VML. I'm finding that IE8 does not display the VML at all when it's in IE8 Standards mode (not using compatibility view).

我的文档类型设置为<!DOCTYPE html> .如果我完全删除了doctype,则IE8会进入quirks模式,并且可以正常工作,但是IE9然后会进入 quirks模式(而不是IE9 Standards),并且不会显示SVG.

My doctype is set to <!DOCTYPE html>. If I take the doctype away entirely, IE8 goes to quirks mode and works fine, but IE9 then goes to its quirks mode (instead of IE9 Standards) and doesn't display the SVG.

这是在测试页上发生的,因此,除了包含div的表单之外,该表单包含< svg> 元素及其子元素或VML元素.

This is happening on a test page, so there's nothing there besides the form containing a div containing either the <svg> element and its children or the VML elements.

这是怎么回事?似乎我不必为不同的浏览器更改doctype,并且Stack Exchange用户页面上的信誉图似乎以相同的方式工作(对于IE8及以下版本为VML,对于其他所有人为SVG,HTML5 doctype)...

What is going on here? It seems like I shouldn't have to change the doctype for different browsers, and the reputation graph on Stack Exchange's user page appears to work the same way (VML for IE8 and below, SVG for everyone else, HTML5 doctype)...

推荐答案

还需要检查其他几件事:

There are a couple of more things you need to check:

行为规则的选择器需要修改.

Selector for the behaviour rules needs to be modified.

  • 设置元素的尺寸或位置时,单位不默认为px.必须明确指定它才能工作.
  • 您不能在DOM之外创建VML元素:

.

var vmlFrag = document.createDocumentFragment();
vmlFrag.insertAdjacentHTML('beforeEnd',
'<v:rect id="aRect" fillcolor="red"         
style="top:15px;left:20px;width:50px;height:30px;position:absolute;"></v:rect>'
);
document.body.appendChild(vmlFrag);

  • 不会显示rect元素!您也不能修改其CSS,因为可能会使浏览器崩溃.但是,有一个解决方法.将元素的externalHTML复制到自身中:
  • .

    var aRect = document.getElementById('aRect');
    aRect.outerHTML = aRect.outerHTML;
    

    这篇关于IE9,IE8,SVG,VML和doctypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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