将IFrame与Meteor一起使用

时间:2013-01-10 23:00:22

标签: iframe meteor

我毫不费力地寻找使用Merame和Iframe的例子。 (请注意,我必须使用iframe而不是DIV,因为最终会有内容)。我试过了两个:

<body>
  {{> hello}}
</body>

<template name="hello">
  <h1>Hello World!</h1>
  {{greeting}}
  <input type="button" value="Click to see what you typed" />
  <br>
  <iframe id="compose" src={{> iframe-content}} height=600></iframe>
</template>

<template name="iframe-content">
  <body>
    <div contenteditable="true">
      Edit me
    </div> 
  </body>
</template>

以递归方式加载,连续创建子iframe。

我也试过

<iframe id="compose" src="content.html" height=600></iframe>

但Meteor将多个HTML文件混合在一起,这也会导致iframe失败。

到目前为止唯一有效的是SRCDOC而不是SRC,但是像FF这样的多个浏览器并没有很好地支持它。

那么,在Meteor中使用iframe的诀窍是什么,最好是在模板中而不是严格地通过代码?

3 个答案:

答案 0 :(得分:7)

您想要'public'文件夹。 Meteor单独留下该文件夹中的内容,如下所述:http://docs.meteor.com/#/full/structuringyourapp

将'content.html'移动到项目/应用程序根目录下名为'public'的文件夹中,并在html中引用它:

<head>
  <title>iframe</title>
</head>

<body>
  {{> hello}}
</body>

<template name="hello">
  <h1>Hello World!</h1>
  {{greeting}}
  <input type="button" value="Click" />

  <iframe src="hello.html"></iframe>

</template>

要明白其他读者,Meteor对iframe没有任何问题。问题在于'content.html'文件的位置是iframe引用的。

答案 1 :(得分:1)

我不明白你的第一个代码示例:

<iframe id="compose" src={{> iframe-content}} height=600></iframe>

据我所知,这不是iframe的运作方式;你必须在src属性中指定一个url,你不能只在那里放置实际的HTML。所以这不会奏效。

至于第二个例子:

<iframe id="compose" src="content.html" height=600></iframe>

如果您没有指定该路径存在,您认为Meteor在哪里获得content.html?由于Meteor默认情况下不设置路由,因此/content.html没有资源。所以你必须添加Meteor Router软件包或一些类似的路由机制,然后告诉Meteor,当被要求提供服务时,它应该只返回一些模板的内容。具有挑战性的部分是弄清楚如何让Meteor返回“真正的”HTML而不是通常提供的Meteor包装的实时HTML结构。

答案 2 :(得分:0)

我最近一直在玩iframe(主要用于封装为应用程序webviews制作的一些页面),如果你将这些html文件放在/public文件夹和iframe src中写绝对URL /file.html然后就行了。