1

に埋め込まれている svg の要素を取得しようとしてい<object>ます。私は svgweb を使用し、フラッシュ ビューアーを強制します。小さなデモ HTML ドキュメントを作成しました。

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
  <script src="svg.js"></script>
  <meta name="svg.render.forceflash" content="true">
 </head>
 <body>
   <!--[if !IE]>-->
    <object data="simple.svg" type="image/svg+xml"
        width="500" height="500" id="testSVG"> <!--<![endif]-->
   <!--[if lt IE 9]>
   <object src="simple.svg" classid="image/svg+xml"
        width="500" height="500" id="testSVG"> <![endif]-->
   <!--[if gte IE 9]>
   <object data="simple.svg" type="image/svg+xml"
        width="500" height="500" id="testSVG"> <![endif]-->
</object>

Flash レンダラーは<object>をに置き換え<div id="testSVG" style="visibility: hidden;" type="image/svg+xml" width="500" height="500" data="simple.svg">ます。

svg は非常に単純です。

 <svg  xmlns="http://www.w3.org/2000/svg"
      xmlns:xlink="http://www.w3.org/1999/xlink">
  <rect id="rect" x="10" y="10" height="100" width="100"
      style="stroke:#ff0000; fill: #0000ff"/>
 </svg>

ここで<rect>、マニュアルに従って - 要素を取得しようとします ( http://svgweb.googlecode.com/svn/trunk/docs/UserManual.html#manipulate_objects ):

var obj = document.getElementById('testSVG');
var doc = obj.contentDocument; // grab the document object inside your SVG file
var myRect = doc.getElementById('myRect');

ie9 は、オブジェクトがプロパティまたはメソッド「getElementById」をサポートしていないことを示しています。

これもクロームでやってみました。上記の代わりに<div>、Flash レンダラーは<embed src="/svg.swf" quality="high" wmode="transparent" width="500" height="500" id="testSVG" name="testSVG" swliveconnect="true" allowscriptaccess="always" type="application/x-shockwave-flash" flashvars="uniqueId=testSVG&amp;sourceType=string&amp;clipMode=both&amp;debug=true&amp;svgId=testSVG" pluginspage="http://www.macromedia.com/go/getflashplayer" style="visibility: visible; " class="embedssvg">.

doc.getElementById('myRect')オブジェクトを返します。Firefox では、 をobj.contentDocument返しますundefined

十分なネイティブ svg サポートがあるので、chrome と ff は気にしません。しかし、svg の要素を取得するには ie9 が必要です。私は何を間違っていますか?

4

0 に答える 0