I am working on an app that will be deployed to Facebook therefore viewed from an iframe inside of Facebook's chrome.
I have some basic media queries that linearise the content at a set viewport size.
When the site is viewed in the browser locally the media queries work fine but when tested inside Facebook's chrome then they do not work.
I assume that the resizing of the viewport is not detected by the child of the iframe therefore the media queries will have no effect. Is there a way to get this working?
A responsive iframe will render well across a variety of devices and screen sizes. In order to make your embedded iframe responsive, you need to wrap the iframe in a div and apply inline css. Follow these simple steps: Get the iframe embed code and paste in into your HTML page.
HTTPS. Websites that begin with https can in most instances be embedded as iFrames. The exception to this is where the original website does not allow itself to be embedded.
You could add a little jQuery to detect a window resize and then swap out a separate stylesheet.
$(window).resize(function(){
var currentWidth = $(document).width();
var allStyleSheets = $("link");
allStyleSheets.each(function(){
var $this = $(this);
//assume sheet1.css is for pages with widths equal and over 700 and sheet 2 is for widths under 700px
if(currentWidth >= 700 && $this.attr("href").indexOf("sheet2.css") > 0){
$this.remove();
$(head).append('<link href="sheet1.css" type="text/css" rel="stylesheet" />');
}
if(currentWidth < 700 && $this.attr("href").indexOf("sheet1.css") > 0){
$this.remove();
$(head).append('<link href="sheet2.css" type="text/css" rel="stylesheet" />');
}
});
});
As my adapted code was using media queries in a common CSS file, I prefer to toggle a fbIframe
class on the body
element, and add specific CSS rules in context of this class. The jQuery code thus becomes simpler:
function adaptToWindowSize(){
$("body").toggleClass("fbIframe", $(window).width() < 820);
};
$(window).resize(adaptToWindowSize);
$(adaptToWindowSize);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With