简体   繁体   中英

Width of page in iframe

I have a parent page and inside that parent page, there is an iframe that is around half the size of the parent page.

The JavaScript in the iframed page is supposed to get the size of the iframed page and set the size of a text input, but both JavaScript's document.body.clientWidth and jQuery's $(document).width() are returning the parent page's width.

How do I get the width of the iframed page from scripts inside the iframe (that is, without having to send the iframe width from the parent page to the iframe page with querystrings)? They are cross-domain too.

只需使用-

<iframe src="demo_iframe.htm" width="200" height="200"></iframe>

The similar kind of work is done here stackoverflow.com/questions/7808729/… you can refer this if it works – Manoj Singh

Thank you, this is exactly what I wanted!

EDIT: Sorry, after a bit of testing, this doesn't work too well. In jsfiddle it works, but in my page, it only gives me the height accurately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM