displaying svg using the embed tag in ie9
Hey everyone, I was just wondering whether anybody had any experience with displaying svg in ie9 using the embed tag. Below is an example of my code:
<!DOCTYPE html>
<html><head><title>Example</title></head>
<body>
<embed id="E" height="50%" width="100%" src="example.svg">
</body>
</html>
Right now this displays just fine in Firefox, ie 8 with the Adobe plugin, however in ie 9 it just pops up a blank box with an image icon in the top left of the box. Does anybody have any ideas how I开发者_JAVA百科 could fix this problem?
Althought your snippet includes a HTML5 DocType definition there are other factors which affect exactly how IE9 processes your HTML e.g. HTTP Response Headers (see How Internet Explorer Chooses Between Document Modes)
I think if you force IE9 into Standards mode your SVG will be rendered by IE9; to quickly test this just use the Developer Tools to control Browser and Document modes.
So, if your embdeded SVG now shows you're just left with figuring out what's triggering IE9 to select the wrong Document Mode.
I'm not sure if your question means that you're trying to figure out any way to display SVG in IE9, or specifically only with the <embed>
tag. If you just want a way to display SVG in IE9, I recommend embedding SVG directly in XHTML5:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<title>untitled</title>
<style type="text/css" media="screen">
body { background:#eee; margin:1em }
svg { background:#fff; display:block; border:1px solid #ccc; width:100%; margin:1em -1px }
</style>
</head><body>
<svg viewBox="-500 -500 1000 1000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full">
<!-- SVG content here -->
</svg>
<script type="text/javascript"><![CDATA[
var svg = document.getElementsByTagName('svg')[0];
var svgNS = svg.getAttribute('xmlns');
// Access/manipulate your SVG here
]]></script>
</body></html>
If you want to test this technique, here are some examples (on my site) using SVG that work in IE9:
- http://phrogz.net/svg/rainbowgrid.xhtml
- http://phrogz.net/svg/3-point-circle2.xhtml
- http://phrogz.net/svg/stirling_numbers.xhtml
- http://phrogz.net/svg/soldiers.xhtml
- http://phrogz.net/svg/drag_under_transformation.xhtml
- http://phrogz.net/svg/complex_butterfly.xhtml
If this is not what you want, please clarify what your needs are.
精彩评论