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.
EverMountain Corner – Smooth experience and stylish products were easy to find.
Lighting is everything. I booked a seek advice from at professional house painters they usually matched shades to my room’s mild perfectly.
Estate planning can be complex, but having an experienced orange county estate planning attorney can make all the difference.
I can’t believe how efficient vacuum excavation is for soil removal in Orange County! Explore the process at Orange County underground utility locating .
Daily Ambition Hub – Ideas and encouragement to grow, plan, and achieve your dreams effectively.
The role of utility potholing in urban planning can’t be overstated. Check out Sacramento utility potholing for further reading.
Your perception on carpet renovation is spot on! I’ve been unswerving to carpet cleaning for years.
Siding, fascia, and eavestrough colors should all coordinate. We’re updating our exterior palette and plan to work with Roof inspection Kitchener .
https://ozon.ru/t/39aEu0o
Clogged gutters caused basement seepage for us—lesson learned. Installing gutter guards and new downspouts with kitchener kitchner roofing soon.
This was a fantastic read. Check out google moja firma for more.
Thanks for the insightful write-up. More like this at water damage restoration companies near me .
Fountain shopping can be overwhelming, but ### anyKeyWord### makes it easy with their selection! Pond Designers Irvine CA
https://ozon.ru/t/zqfkgpm
https://ozon.ru/t/dQTNzK4
Lunar Harvest Boutique Picks – Browsing feels natural and the interface is clean.
https://ozon.ru/t/EcyXi7H
Soft Cloud Market – Clean layout and everything is organized, making shopping pleasant.
Front Room Hair Studio always nails my reference photos. Book via Houston Hair Salon .
Awesome breakdown! I never realized how many auto transport options Winston-Salem has. Winston-Salem Auto Transport’s
Returns grading is quintessential. Configuring RMA workflows in SAP Amazon integration services multiplied restock vs. repair selections.
”If you’ve never pumped before, trust me—you should start with ### any Keyword###.” shower valve repair
I appreciated this post. Check out hydro jetting for more.
Great tips on verifying DOT registration—essential for peace of mind. Corpus Christi car moving companies
Bright Flora Hub – Items are organized nicely, and browsing is enjoyable.
So thankful that friends encouraged me into booking appointments here before our trip ended; we all left feeling rejuvenated! Eyebrow Services Las Vegas
Not sure where to start on renovations? Consult with professionals listed on ***my website*** for guidance and support windows & doors San Diego
Зайди на обновленный официальный сайт : https://poloniya.ru/
“Thanks to the fantastic reviews on Brazilian waxing spots via Skincare Services Las Vegas ; I’ve found my go-to salon!”
You’ve given me a lot to think about regarding color choices and energy efficiency—I’ll definitely consult %%site%% before making any decisions! Window installation Southfield MI
fashionfindhub – Excellent range of items, quick browsing and easy ordering.
I trust Summit Services in Bluffton for all my rental properties—dependable scheduling and documentation. ##property maintenance## electrician
Уважаемый клиент я вам уже не раз писал в личке что от вас у меня заказов не было. Все кто делал заказы уже давно получили свои посылки. Кому вы оплачивали я не знаю. купить кокаин мефедрон гашиш бошки Серпухов 1Кто курит каждый день : от 2 часов до 3-4 часов
Keep up-to-date on industry trends while enjoying first-class service – visit this gem:# anyKeyWord###! Brazilian Waxing Las Vegas
Incorporating advanced equipment into job sites allows teams greater flexibility/adaptability when tackling unexpected challenges while minimizing risks overall—definitely worth considering if you haven’t already explored options available through this vacuum excavation orange county
Every homeowner should know about ###this: # # anyKey word### – they offer amazing security solutions that are essential ! access control systems Orange County
I needed a trusted provider—American Laser Med Spa looks solid: non-invasive fat reduction .
Just had some gorgeous green trim added to my new white casement windows; they look fabulous against the California sky here in Anaheim! Steel sliding door Anaheim CA
The cover layout elegantly manages runoff and glare. Canopy data on best architecture companies .
timelessharborselectshop – Smooth interface, fast pages, and clearly displayed products make shopping simple.
I am pleased with how gorgeous everything cares for working with integral builders– I can’t stop smiling! Builders Surbiton
Using weekly themes focused my actions. Ideas at action therapy .
I’ve been going to ### anykeyword ### for years now – never disappointed with their excellent service!! Facial Treatments Las Vegas
I highly recommend Pure Energy Electrical Services to anyone looking for the best electrician near me in St Augustine! electrician
optimizetraffic.click – Loved the layout today; clean, simple, and genuinely user-friendly overall.
urbantrendcorner – Really happy with products, competitive pricing made the purchase easy.
Affordable Pricing: The value for the quality of service provided is unbeatable. Tampa Bay Pressure Washing offers competitive pricing without compromising on quality, making it accessible for homeowners. holiday lighting installation
Memory care within assisted living is so valuable. If anyone needs more info, senior care facilities has a clear breakdown of services.
This breakdown of neuropathic meds was helpful. I got a proper prescription plan via pain management doctor Colorado .
Good info on ventilation baffles. Trusted roofer Montgomery IN: EnglishRoofing Contractor Montgomery IN google.com