在Rails应用程序中检测iframe请求 [英] Detect iframe request in a rails app

查看:283
本文介绍了在Rails应用程序中检测iframe请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iFrame工具,它应该以我的页面以其他格式呈现。所以我想检测来自iFrame的请求,就像我可以从iPhone中检测到它们一样。这是可能的?



请求头中是否有特殊提示,我可以使用,或者我可以手动输入吗?

感谢
Markus

解决方案

当您收到来自iPhone的请求时, User Agent - 类似于 Mozilla / 5.0(iPhone; U;像Mac OS X的CPU; Apple)AppleWebKit / 420 +(KHTML,如Gecko)Version / 3.0 Mobile / 1A543a Safari / 419.3 code> request.user_agent 变量。在这个字符串中搜索 iPhone 可以告诉你一个iPhone正在访问你的页面。


$ b iframe是一个 HTML标记将页面中的其他页面包含进来(例如Facebook的按钮使用这个按钮)。这不需要特定的浏览器,所有的现代浏览器都支持这一点。你不能告诉服务器端你的页面是否在iframe中调用。您可以在客户端使用一些JavaScript来查看您的当前页面是否位于iframe中,然后向服务器发送通知。最好的做法是在你的请求中添加另一个参数,比如 iframe = 1 ,并在你的内部使用这个参数控制器。

I have a iFrame tool, which should get rendered in a other format than my page. So I want to detect requests from iFrame like I can detect them from a iPhone. Is this possible?

Is there a special hint in the request header, that I could use, or could I manually enter one?

Thanks Markus

解决方案

When you get a request from an iPhone there will be send a "User Agent"-String like Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 in the request.user_agent variable. Searching this string for iPhone can tell you that an iPhone is visiting your page.

An iframe is an HTML tag to include other pages within your page (eg. the Facebook like button uses this). This does not have to to anything with a specific browser, all modern browsers support this. You cannot tell on server side whether your page was called within an iframe or not. You can use some JavaScript in the client to find out if your current page is within an iframe and then send a notice to the server.

Best practice would be to add another paramter to your request like ?iframe=1 and use this param within your controller.

这篇关于在Rails应用程序中检测iframe请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆