Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect iframe request in a rails app

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

like image 398
Markus Avatar asked Aug 02 '11 07:08

Markus


1 Answers

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.

like image 184
arnep Avatar answered Sep 20 '22 03:09

arnep