Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to Change the width/height of an iframe from within

I am going to host my app in a site. The app will be shown inside an iframe in it. i need my app to be on full screen, is there anyway where I can change the size of that iframe which will hold my app from my application?? My app and the site hosting it are not the same domain.

$("iframe", window.parent.document).css("width", "1000px");

this is not working as the site and app do not belong to same domain

like image 888
Vignesh Subramanian Avatar asked Aug 15 '13 07:08

Vignesh Subramanian


People also ask

How can I set my iframe height width and 100%?

To get the iframe to properly use 100% the parent needs to be 100%. In newer doctypes the html and body tag are not automatically 100%. When I added height:100% for html and body then it worked flawlessly.

How do you change the position of an iframe?

position: absolute; This will give the iframe a position relative to the wrapper and let it be positioned over the padding of the wrapper. top: 0 and left: 0 are used to position the iframe at the center of the container. width: 100% and height: 100% make the iframe take all of the wrapper's space.


2 Answers

The sanest way, if your app needs to run full screen, is to break out of the iframe. That is, detect if your page is in an iframe, and if so, redirect the browser to your page so that is is no longer in the iframe!

This page explains how to do it:

<script type="text/javascript">
    if (top.location!= self.location) {
        top.location = self.location.href;
    }
</script>
like image 124
Mr Lister Avatar answered Oct 20 '22 03:10

Mr Lister


If you control both pages then you can use HTML5 Post message:

outside:

$(window).bind("message", function(e) {
    $('iframe').attr({
        width: e.originalEvent.data.width,
        height: e.originalEvent.data.height
    });
});

inside:

$('button').click(function() {
    parent.postMessage({width: '200px', height: '200px'}, 'http://localhost');
});
like image 28
jcubic Avatar answered Oct 20 '22 03:10

jcubic