Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsively embed Bootstrap webpage in an iframe

I am working on a SaaS application, which essentially provides a full webpage to the client. The client can access their page at: http://client.myapp.com . However I want to allow clients to embed this page easily on their website. At the moment I just provide an iframe embed code with stylesheet to reset the margin of the body tag.

<head>
<style type="text/css">
html { overflow: auto; }
html, body, div, iframe { margin: 0px; padding: 0px; height: 100%; border: none; }
iframe { display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden; }
</style>
</head>

<body>
<iframe id="myapp" name="myapp" src="https://client.myapp.com" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
</body>

However when they include the iframe, the page is no longer responsive. How can I replicate the responsiveness of the original webpage when using an iframe (or any other way you might suggest) ?

like image 346
Anton Evangelatov Avatar asked May 14 '14 10:05

Anton Evangelatov


1 Answers

So I found two solutions to the problem:

Solution 1:

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>body { margin: 0px; } .embed-container { position: relative; padding-bottom: 100%; height: 0; overflow: hidden; max-width: 100%; min-height: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style>
</head>
<body>
<div class='embed-container'><iframe src='https://client.myapp.com' style='border:0;'></iframe></div>
</body>

Solution 2:

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
/* Using http://npr.github.io/responsiveiframe/ */
<script src="jquery.responsiveiframe.js"></script>

<script type='text/javascript'>
$(function() {
  $('iframe').responsiveIframe({xdomain: '*'});
});
</script>

<style>
body {
  margin: 0;
}
</style>
</head>

<body>

<iframe src='https://client.myapp.com' style='border:0; width: 100%; height: 100%;'></iframe>

</body>

So far it appears both work just fine on a desktop browser (Chrome, Firefox) and on my mobile (Android 4)

like image 62
Anton Evangelatov Avatar answered Sep 22 '22 07:09

Anton Evangelatov