javascript - 内联 SVG 与 <object> 嵌入式

标签 javascript ruby-on-rails svg html4

我正在为 Eve Online 构建一个游戏内浏览器 RoR 应用程序。我的应用程序的要求之一是显示由 graphviz 生成的 SVG 图形。我在这个环境中无法满足我的要求。

Eve 的 IGB 没有官方文档,但 wiki 指出:

The new EVE Online in-game browser (code-named Moondoggie) is based on a technology stack combining two elements:

Awesomium: A middleware layer that delivers rendered webpages as data parseable by a 3D engine. Awesomium is developed by Khrona Software.

Chromium: A middleware layer that provides interprocess communication, webpage rendering, HTTP communications, and all the other basics needed for writing a web browser. It is, itself, based on Apple’s Webkit framework. Chromium is an open-source project championed primarily by Google.

Because of this, Moondoggie is able to pass the Acid3 test and thus can support the full HTML 4.01 and CSS3 specifications.

我需要包含在 SVG 中的链接才能访问我的应用程序的 javascript。用 <embed> 嵌入它或 <object>将 SVG 置于我的 JS 文件的范围之外。

使用 <embed><object>确实在游戏内浏览器中正确渲染 svg。当它像下面这样内联时,它会显示一行文本,其中仅包含 SVG 中的文本元素。

更新 这就是我所在的位置。我很确定其中大部分都是多余的,因为我没有注意到仅使用 render file: 有什么不同。在我自己看来。我认为 mime 类型注册更适合与 respond_to 一起使用,但我不确定在这种情况下如何使用它。

主视图片段:

<%= render "map/map" %>

部分 View 文件:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:svg="http://www.w3.org/2000/svg">
<head>
    <title>Embedded SVG</title>
</head>
    <body>
        <%= render file: @map.output_file_path %>
    </body>
</html>

配置/初始化程序/mime_types.rb:

Mime::Type.register "image/svg+xml", :svg  

我不明白为什么它在 <object> 中渲染得很好标记但不是内联时。如何模拟 <object> 中的环境在我的主要观点?或者,我怎样才能给出 <object>标记访问我的 javascript 函数?

最佳答案

可以从父文档访问 中的文档。这是 ACID3 仍在测试的(太少的)svg 事物之一。

Here's an example如何从父 html 文档中的脚本修改 svg 文档。

关于javascript - 内联 SVG 与 <object> 嵌入式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15980971/