Yesterday I was working on a site that needed an iframe embedded in the page whose content came from a completely different domain. I try to steer clear of iframes at all costs normally so forgive me if what I’m about to say is pretty obvious.
I didn’t want the content in the iframe to appear as though it was in an iframe, so obviously I stripped off all the default browser styles…well, the border. I wanted the iframe to be as high as the content it was containing so that no scroll bars would appear.
So what I did was just give the iframe a height, however when the user navigated to a different page within the iframe, the height I had previously set was too big or too small.
I instantly thought “right, JavaScript will sort this out for me!” and proceeded to quickly code up a function that would inspect the scrollHeight of the content in the iframe and adjust the iframe height accordingly.
No! Said cross domain policy. I had momentarily forgotten all about that. Since the iframe content came from a different domain, I wasn’t allowed to access the document object of the iframe (or vice versa).
Firefox says “Error: Permission denied to access property ‘document’” and other browsers similar.
I started searching for some kind of workaround. Of course there isn’t really one…except I did find an interesting hack for Firefox. Which is – an iframe document can alter the url fragment of the parent window’s location object! ha madness.
The idea is that the document in the iframe alters the url fragment to read:
http://freestyle-developments.co.uk/blog/?p=150#138
Where 138 is the height of the iframe document (obviously you could be a bit more fancy and send other parameters and name them e.g #height:138 but for simplicity I’ve just set the value). The parent then reads this value and sets the iframe height accordingly:
var iFrameHeight = parseInt(location.hash.replace('#', ''));
So…yeah, that’s pretty interesting, but not really a solution. Check out the example implementation here.
Anyway, what to do? HTML5 web messaging to the rescue! Sweet! HTML5 web messaging is cross domain messaging done right. Not only does the messenger choose who should receive messages, but the recipient also chooses who to receive messages from.
The idea is that after the iframe document has loaded, it sends a message to the parent window telling it what it’s scrollHeight is. The parent listens for messages, and sets the height of the iframe when it receives a message.
A couple of things to note:
- There has to be communication between the two documents. i.e. the document on the external domain needs to actively send this message. Which can be a complete show stopper if you have no control over the document on the external domain
- This isn’t going to work on IE < 9. I tested the implementation linked below is working on FireFox 4 (Beta 7), Safari 5.0.2, Chrome 8, Opera 10.63 and Internet Explorer 9 Platform Preview 7. Which is a pretty good spread to be honest
Check out the example HTML5 web messaging implementation here.
Great observations made surrounding developing an online presence centered around natural user acquisition methods proven effective thanks largely due contributions made by firms such as #WebJuice#-I’ll look further into ### anykeyword ###!! Organic leads generation
Bạo ngược động vật không chỉ phản cảm mà còn vi phạm pháp luật. Nếu gặp nội dung như vậy, hãy báo cáo và tìm cách xử lý an toàn tại xem sex nhật bản không che .
Grateful understanding there’s anybody who cares in truth approximately buyer pride general!!!Explore trending discussions going down excellent now simply by: ### anyKeyWord ### Plumber Norwich
Summit Services provided exceptional service as my electrician near me in Bluffton. You won’t be disappointed! electrician
Nội dung bạo lực học đường có thể gây tái chấn thương cho nạn nhân. Tài nguyên hỗ trợ tâm lý và kênh báo cáo ẩn danh nằm ở thưởng thức phim sex mới 2025 .
Love that CoolSculpting requires no downtime. Read more from American Laser Med Spa at non-surgical fat removal near me .
Автором книг является человек который создает литературные произведения такие как романы рассказы или стихи. Чаще всего таких людей называют писателями поэтами или литераторами. Buchautorin— это создатель произведения чьим творческим трудом оно создано
ЦВЗ центр https://cvzcentr.ru в Краснодаре — команда специалистов которая работает с вегетативными расстройствами комплексно. Детальная диагностика сопровождение пациента и пошаговый план улучшения самочувствия.
ЦВЗ центр https://cvzcentr.ru в Краснодаре — команда специалистов которая работает с вегетативными расстройствами комплексно. Детальная диагностика сопровождение пациента и пошаговый план улучшения самочувствия.
They explained everything clearly. Highly recommend the top rated plumber in San Jose CA. More info at jb rooter and plumbing reviews .
The tailored approach of Local SEO Seattle WA really sets them apart from other SEO firms in Seattle.
Action therapy puts you back in the driver’s seat. Learn how at action therapy winnipeg .
Planning a new industrial facility? The comprehensive planning checklist from Select Garage Doors at New Garage Door Installation is a must-read before making decisions.
Новичка 1к10 само то https://leylailyasova.ru/solikamsk.html Я выхватил бан ты злобняк
Nairabet offers https://nairabet-play.com sports betting and virtual games with a simple interface and a wide range of markets. The platform provides live and pre-match options quick access to odds and regular updates. Visit the site to explore current features and decide if it suits your preferences.
Nairabet offers https://nairabet-play.com sports betting and virtual games with a simple interface and a wide range of markets. The platform provides live and pre-match options quick access to odds and regular updates. Visit the site to explore current features and decide if it suits your preferences.
Your suggestions about eco-friendly materials are exactly what I need for my upcoming renovation project—more green ideas at Kitchen Remodeling Services In Los Angeles !
The brick whitewash appears to be like balanced and natural and organic. See a precision conclude expert painter mindset at painting companies near me .
My gutters have never looked better thanks to Clare Gutter Cleaning Company! Their satisfaction guarantee is just the cherry on top! Gutter repair Limerick
The medical bills stack up quickly. A Garland Truck Accident Lawyer at Garland car accident lawyer can pursue future care costs too.
Thanks for the practical tips. More at projektowanie stron internetowych .
Modern Harbor Hub Online – Products are easy to locate and the site feels responsive.
Well done! Find more at https://maps.app.goo.gl/6RChGSrFnbLTgVGt7 .
It’s amazing how a creative design on a simple business card can leave such a strong impression. I’ve used Print FX for custom print projects and discovered Direct Mail Services through their team—so convenient!
Charcuterie, tasting menus, and chef’s tables— fine dining helped me locate the right fine dining match.
It’s great to have reliable electricians like Pure Energy Electrical Services right here in St Augustine! Best service ever! electrician
Your Daily Creative Hub – Explore new activities and innovative projects to boost your creativity.
This was very beneficial. For more, visit https://maps.app.goo.gl/qhxyoR1icFjyBqQd9 .
It’s good understanding there’s a reliable choice like * * anyone * * offered whenever we need them. porta potties near me
If you need porta potties for building sites in Phoenix, porta potties near me has you covered with their long lasting options.
I always suggest renting portable toilets for outdoor events. Riverside homeowners need to definitely look into porta potty rental !
For anyone looking for reliable roofing services, I highly recommend checking out Gutter Repairs Surrey !
uniquebuypicks – Great variety, shopping was enjoyable and hassle-free.
I hadn’t considered how tactile paper choices can impact a restaurant’s vibe. Textured stock can make a huge difference. If anyone is interested in exploring more options, Decals and Stickers and Print FX are worth checking out.
Helpful comparison with liposuction. I prefer American Laser Med Spa’s non-surgical CoolSculpting. non-surgical body sculpting
Smart advice. Cleveland Ohio chimneys benefit from annual inspections, with repairs handled before deep freeze. find masonry experts near me
Such valuable insights into local SEO tactics! If you need help implementing them, reach out to SEO Expert San Jose CA based in San Jose!
Автором книг является человек который создает литературные произведения такие как романы рассказы или стихи. Чаще всего таких людей называют писателями поэтами или литераторами. Buchautor— это создатель произведения чьим творческим трудом оно создано
Full Circle Treasures – Items are easy to locate with a smooth browsing experience.
Rippling effects felt beyond immediate circles once information spreads further reaching desired audiences!!!! ## SEO Agency San Francisco CA
trendcentralhub – Loved the trendy items, the website loads very quickly.
Legal jargon can be tough but not when explained by professionals from ## probate attorney orange county
If your downspouts are pooling water near the foundation, it’s a red flag. We’re planning extensions and new troughs— Kitchener roofing experts looks like a solid local option.
Автором книг является человек который создает литературные произведения такие как романы рассказы или стихи. Чаще всего таких людей называют писателями поэтами или литераторами. Schriftsteller— это создатель произведения чьим творческим трудом оно создано
If you’re in Arlington and need appliance repair, this is the place to go! Quick and reliable. Appliance repair service
tradition contracting does right paintings on my condominium
tradition contracting eavestrough & roofing kitchner roofing
kitchner roofing customized contracting eavestrough & roofing
custom-contracting roofing contractors in Kitchener
Remembering histories lost not only inspires actions taken today but serves reminder why vigilance matters across generations moving forward through time indefinitely ahead ! Biohazard Clean Up
зашел на сайт не нашел там 307 купить кокаин мефедрон гашиш бошки Магадан А вообще читай раздел рецепты там все очень подробно расписано в нескольких темах причем
Appreciate the protected nightlife guidelines. I most likely determine activities vetted on organic seo solutions in san jose .
This is a must-read for anyone needing roof repairs in Illinois! Thanks, will check out Roofing Contractors Illinois !