Chaitanya
Chaitanya

Reputation: 729

iframe contentWindow undefined even after .load function

I want to set the height of the iframe match it's content. But iframe.contentWindow returns undefined even after putting it inside .load(). Here's the code:

$(document).ready(function() {
    var myIFrame = $('#iframe');
    console.log(myIFrame.contentWindow); //getting undefined
});

Can someone tell me what's wrong in this? Thanks a lot.

Upvotes: 1

Views: 4364

Answers (1)

Chaitanya
Chaitanya

Reputation: 729

Alright, so contentWindow is native Javascript and since I'm using jQuery, I'll have to get the original DOM object first. The correct way to get contentWindow :

var win = $('#iframe').get(0).contentWindow;

For More Information

Upvotes: 2

Related Questions