4

I'm trying to display SVG, using <object>, in Firefox.

If I load the index.xhtml locally, rather than through a HTTP server, the page loads correctly.

However, if I load through a HTTP server, Firefox displays nothing, but rather informs me a plugin is required.

I've spent about two hours looking for and trying different solutions, to no avail. I'm now extraordinarily annoyed and frustrated.

This is the page;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:svg="http://www.w3.org/2000/svg"
      xmlns:xlink="http://www.w3.org/1999/xlink">
  <head>
    <title>Daily Agera Stats</title>
  </head>

  <body>
    <table cellpadding="4" style="margin-left:auto; margin-right:auto">
      <tr>
        <td><object data="clicks_with_data_per_day_all_sources.svg" type="image/svg+xml"></object></td>
        <td><object data="clicks_with_data_per_day_criteo_only.svg" type="image/svg+xml"></object></td>
        <td><object data="impressions_per_day_with_data.svg" type="image/svg+xml"></object></td>
        <td><object data="impressions_per_day_with_data_from_clickers.svg" type="image/svg+xml"></object></td>
      </tr>

      <tr>
        <td><object data="referrer_urls.svg" type="image/svg+xml"></object></td>
        <td><object data="conversions_per_day_with_data.svg" type="image/svg+xml"></object></td>
        <td><object data="conversions_per_day_with_data_from_clickers.svg" type="image/svg+xml"></object></td>
        <td></td>
      </tr>
    </table>
  </body>
</html>

Note that the WWW server (lighttpd) has been configured to serve .xhtml as "application/xhtml+xml".

Given the page works off-line, I'm guessing this is a MIME issue of some kind. The total absence of meaningful documentation or error messages or anything one might consider an intuitive solution is INCREDIBLY ANNOYING.

The SVG is generated by GnuPlot and is quite long. The head looks like this;

<?xml version="1.0" encoding="utf-8"  standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg 
 width="320" height="256" 
 viewBox="0 0 320 256"
 xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
>

<title>Gnuplot</title>
<desc>Produced by GNUPLOT 4.6 patchlevel 0 </desc>

Any help deeply appreciated.


You should look into using Flask -- it's an extremely lightweight interface to a WSGI server (werkzeug) which also includes a templating library, should you ever want to use one. But you can totally ignore it if you'd like.

4

1 に答える 1

3

私は答えを見つけました。

<object> タグで MIME タイプが指定されているにもかかわらず、.svg の MIME タイプを提供するように HTTP サーバーを構成する必要もあります。

もちろん、私はこれをほぼ最初に見ていましたが、私は思っていました-HA!- 私は実際に型を指定していたので、ブラウザは何をすべきかを知っているでしょう。

ブラウザが type 属性を無視した場合、一体何の意味があるのでしょうか?

于 2012-05-02T16:18:53.503 に答える