How can I use VML in a webpage?
I wanted to use VML to draw shapes in IE.I came up with the following code but it does not display me anything in IE8..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona开发者_StackOverflowl.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>v\: * { behavior:url(#default#VML); display:inline-block }</style>
<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v" />
</head>
<body>
<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>
<object id="VMLRender" codebase="vgx.dll" classid="CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E">
</object>
<v:rect style="width: 1in; height: 1in; left: 0.5in; top: 6in; rotation:0deg" fillcolor="#ffff00" strokecolor="#ff0000"/>
</body>
</html>
VML changed in IE8: Changes in VML for IE8
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=5" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>v\: * { behavior:url(#default#VML); }</style>
</head>
<body>
<v:rect style="width: 1in; height: 1in; left: 0.5in; top: 6in; rotation:0deg" fillcolor="#ffff00" strokecolor="#ff0000"/>
</body>
</html>
I would strongly recommend not using VML.
VML is only supported in IE. All other browsers support SVG instead, and even in IE, IE9 now supports SVG and only supports VML effectly as a legacy feature.
Of course, that doesn't help you if you're trying to support IE version 8 and earlier, as they only have VML and not SVG. However, there are a number of Javascript libraries which allow you to work with SVG and will convert on the fly to VML for IE, which means that of you use SVG, you can write code that works in all browsers.
The best of these libraries is Raphael. It is a true cross-browser vector graphics library, defaulting to SVG, but with fallback to VML where required, and covering up all the browser inconsistencies with a consistent tool set, completely transparent to both you the developer and to your users.
Another library to consider is SVG2VML. There are a number of others you can find with a bit of googling too.
Hope that helps.
精彩评论