0

I'm trying to capture div#map-canvas from my site, www.RichBlocksPoorBlocks.com, to make an iframe that people can embed anywhere.

Here's my iframe

<iframe src="http://www.richblockspoorblocks.com#map-canvas" style="width:600px; height:400px;"></iframe>

It goes to div#map-canvas, but it also loads the rest of the page as well. I'd like that div to be the only thing in the iframe.

Is this possible with an iframe?

4

3 回答 3

1

要实现这一点,创建一个单独的 .php 或 .html 文档会更容易,其中仅包含您要在 iframe 中显示的部分并排除其他所有内容。

因此,不是 iframe 指向“ http://www.richblockspoorblocks.com#map-canvas ”,而是指向类似:“ http://www.richblockspoorblocks.com/map-canvas.php ”的内容。

这将是一种非常快速有效的方式来做你想做的事,并且不需要任何外部库或 javascript。

于 2013-03-28T19:47:07.153 回答
0

When you call http://www.richblockspoorblocks.com#map-canvas the hash will probably cause the browser to look for a corresponding <a name="foo">bar</a> so this won't work using an iFrame.

What I would recommend doing is writing a script which you call from your iFrame which accepts the name of the page fragment to load. I know using jQuery's $.load() you can call an element ID to load a page fragment, and I think it's also possible in PHP too...

于 2013-03-28T19:43:33.090 回答
0

您不能在 iframe 中使用哈希链接。

您可以并且应该使用几行您最喜欢的服务器端语言来创建您想要呈现的特定内容,然后链接到它。这样,您的服务器将只向最终用户发送所需的数据,并且还可以节省带宽和加载时间。

于 2013-03-28T20:03:51.923 回答