Reputation: 2550
On my page, I have an iframe tag that I control. The iframe src attribute points to another page on my domain. Inside this iframe is a Javascript < script > tag that will call code to serve an ad of some sort. The ad is either 300px (w) x 250px (h) or 500px (w) x 500px (h), but I don't know which ad will be served. The ad Javascript has no callback function that I can use to obtain height and width information.
So, this tag is on my page.
<iframe src="http://mydomain.com/page_that_has_ad_code_that_will_run.html" frameborder="0" scrolling="no"></iframe>
Is there a cross-browser way to determine the height of the iframe after the inside Javascript finishes running? Native Javascript or jQuery is fine. Thank you.
I have tried $('iframe').contents().height(); but I'm not sure that is the proper way. (It currently returns a value greater than 250 or 500, so it's probably picking up all the immediate children tags.)
Upvotes: 1
Views: 219
Reputation: 2844
You can access an element of an iframe with the follow code: first you should give your iframe a name, and your ad an id
parent.frames['name_of_iFrame'].document.getElementById('id_of_element').height;
and you should do the same for the width
Upvotes: 1