tylerauerbeck
tylerauerbeck

Reputation: 173

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 could fix this problem?

Upvotes: 0

Views: 5887

Answers (2)

James
James

Reputation: 56

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.

Upvotes: 3

Phrogz
Phrogz

Reputation: 303244

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:

If this is not what you want, please clarify what your needs are.

Upvotes: 1

Related Questions