Quantcast
Viewing latest article 7
Browse Latest Browse All 28

Answer by The Onin for Resizing an iframe based on content

Using jQuery:

parent.html

<body><script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script><style>iframe {    width: 100%;    border: 1px solid black;}</style><script>function foo(w, h) {    $("iframe").css({width: w, height: h});    return true;  // for debug purposes}</script><iframe src="child.html"></iframe></body>

child.html

<body><script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script><script>$(function() {    var w = $("#container").css("width");    var h = $("#container").css("height");    var req = parent.foo(w, h);    console.log(req); // for debug purposes});</script><style>body, html {    margin: 0;}#container {    width: 500px;    height: 500px;    background-color: red;}</style><div id="container"></div></body>

Viewing latest article 7
Browse Latest Browse All 28

Trending Articles