user2198849
user2198849

Reputation: 29

Apply Changes on Parent Iframe

I have an Iframe something like this.

<iframe id="test" src="test.html">

</iframe>

In my test.html I want to add a script to change width and height of iframe.

<script>
    $(document).ready(function() {
       $('#test').attr("width", "510px");
   });
</script>

But its not working.

Upvotes: 0

Views: 66

Answers (2)

Nick R
Nick R

Reputation: 7794

You need to do something like this inside the iframe html page.

Width:

<script>
    window.parent.document.getElementById("test").width = 900;
</script>

Height:

<script>
    window.parent.document.getElementById("test").height = 900;
</script>

Upvotes: 1

Dave Long
Dave Long

Reputation: 9759

Inside the IFrame you can resize the IFrame with this snippet:

<script>
    parent.document.getElementById('test').style.width = "510px";
</script>

Just be careful, when you get into IFrames you'll run into browser security sandboxing, which could cause troubles interacting with content inside the iframe from outside of it or vice versa.

Upvotes: 0

Related Questions