开发者

Different layout for iframe

I have a rails app with content other websites need to access via iframe. The content should have a different layout when shown on the websites (no menu bar et开发者_运维问答c.) I made a new layout file called iframe.html.erb How can I check, whether the page is called form an external iframe so the right layout file is used?


As far as I know when you doing

<iframe src="www.google.pl"></iframe>

you have no control over layout or styles of page display in iframe unless you own the page and can make it look whatever you like.

EDITED

If you displaying your own site go like this:

<iframe src="/some_site_that_i_can_change_code_in?from=iframe"></iframe>

and then in controller of some_site_that_i_can_change_code_in:

if params[:from] == "iframe"
  render :layout => "for_iframe"
else
  render :layout => "normal"
end


A good way to control the specific layout and content when serving an iframe is to register an "iframe" mimetype.

## config/initializers/mime_types.rb

Mime::Type.register 'text/html', "iframe"

Create a view that matches the controller action being served ie: show.iframe.haml. Then, when a request comes in with format: iframe it'll render the iframe version.

That way you can control exactly what's in the iframe on other sites. No need to get crazy in the controller.


I think the only way to do this is with Javascript and then redirect, but it's kind of messy and not really a good idea. See this thread for more info: Detecting if this is an iframe load or direct

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜