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.
Photo and weight tests at % escalate satisfactory. We attached scales to ERP for manufacturing near me to flag weight mismatches.
We had ice dams last year—turns out ventilation and insulation were the culprits. Getting a roofing audit from TPO roofing to fix it before the snow hits.
Great experience with the roofing professionals at Emergency roof repairs —highly recommend them!
New homeowners in Kitchener—don’t skip a roof and gutter inspection. We’re using Roofing near me Kitchener for a comprehensive report and quote.
Very informative article. For similar content, visit kosmetolog .
Скоро откроется в Минске представительство. Как откроется увидите в разделе Представителей купить кокаин мефедрон гашиш бошки Волгодонск продавец шикарный – всё объяснил рассказал.
This was highly educational. For more, visit mejores abogados Coruña .
This was quite informative. For more, visit contador fiscal Saltillo .
Valuable information! Discover more at juicio laboral Sevilla .
Great job! Discover more at colchón visco muelles combinación .
Professional, clean, and effective — my take on American Laser Med Spa. Learn more: body contouring without surgery .
The exposure techniques are gentle yet effective in action therapy. More details at action therapy near me .
fashioncorner – Great variety of outfits, checkout felt very easy and fast.
trafficcrafter.click – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
I appreciated this post. Check out Heating Repair for more.
Проблемы со здоровьем? остеопат для детей: комплексные обследования консультации врачей лабораторная диагностика и процедуры. Поможем пройти лечение и профилактику заболеваний в комфортных условиях без очередей.
Проблемы со здоровьем? невролог центр краснодар: комплексные обследования консультации врачей лабораторная диагностика и процедуры. Поможем пройти лечение и профилактику заболеваний в комфортных условиях без очередей.
conversionedge.click – Color palette felt calming, nothing distracting, just focused, thoughtful design.
ORBS Production https://filmproductioncortina.com is a full-service film photo and video production company in Cortina d’Ampezzo and the Dolomites. We create commercials branded content sports and winter campaigns with local crew alpine logistics aerial/FPV filming and end-to-end production support across the Alps. Learn more at filmproductioncortina.com
Appreciate the helpful advice. For more, visit respite care facilities .
ORBS Production https://filmproductioncortina.com is a full-service film photo and video production company in Cortina d’Ampezzo and the Dolomites. We create commercials branded content sports and winter campaigns with local crew alpine logistics aerial/FPV filming and end-to-end production support across the Alps. Learn more at filmproductioncortina.com
clickrevamp.click – Bookmarked this immediately, planning to revisit for updates and inspiration.
CIS Controls v8 remain a pragmatic baseline. Even enforcing the 1st six can curb hazard. I’ve created a immediate-delivery equipment at managed it services near me .
Helpful stuff. When our sewer line cracked, jb rooter and plumbing ca offered trenchless options.
Good overview. Chimney waterproofing repair in Cleveland Ohio protects against freeze-thaw damage year-round. masonry work in my area
Thanks for the useful suggestions. Discover more at water heater installation near me .
1. Hey, great article! As someone from Ontario just getting into online slots, I’ve been trying to wrap my head around RTP rates. What’s a good RTP for a beginner like me to look for? I want to have fun but avoid blowing my budget too quickly https://wiki-triod.win/index.php/Are_Crypto_Casinos_Safe_for_Canadians%3F_What_Will_Change_Within
digitalkickstart.click – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
Helpful suggestions! For more, visit Personal Injury Lawyer .
This is why content and links must work together. Our outreach through SEO Agency secured authoritative placements that lifted an entire category.
For a sophisticated date night, I sifted through Charleston romantic restaurants on charleston gourmet dining .
The section on peroneal tendon tears was excellent. Surgical repair options at Caldwell foot and ankle surgeon .
Your insights into the craftsmanship behind cork slate roofs are truly inspiring—thank you! Drone roof inspections
Impressive adaptive reuse frame of mind. We explored related retrofits on architects near me .
Appreciate the great suggestions. For more, visit water heater repair services .
This article convinced me to address leaning trees. I requested a quote at Tree Service .
Standard SEO audits in the US often feel like running through a checklist in a manic rush—“meta tags? ✅, alt texts? ✅, backlinks? ✅”—but they completely miss the forest for the trees performance analysis service solutions
Great explanation of coinsurance on commercial policies. Insurance agency Huntsville helped avoid penalties.
Can anyone recommend which areas are best suited for #Cool#@ treatments? kybella double chin treatment
Just got a fantastic Brazilian wax at Eyebrow Services Las Vegas —definitely the place to go when you’re in Las Vegas!
Flooded utility room? Central replaces failed washing machine hoses with braided lines. Prevent disasters at emergency plumber in southampton .
Been through my fair share of US crypto exchanges, and honestly, fees are where most people get burned if they don’t look close. Coinbase might seem user-friendly, but their withdrawal and trading fees can quietly slice off 1 review of Bitstamp exchange
WildSand Online – Beautiful collection, easy browsing, and very fast delivery today.
The brain can heal with fortify. Evidence-headquartered treatment options reachable as a result of drug rehab sell long-term trade.
free adult chat 321chat login
If you’re in Orange County, don’t miss out on the great deals at backyard hardscape contractor orange county for BBQ islands!
бонуси казино бонуси в казино
The scope of loss structure right here is sturdy. I used the pattern from claims adjuster service .
но чет с каждым разом доставка все дороже и дороже купить кокаин мефедрон гашиш бошки Сарапул Хмм…странно всё это но несмотря ни на что заказал норм партию Ам в этом магазе так как давно тут беру.Как придёт напишу норм репорт про Ам
Jumping into crypto through beginner-friendly US exchanges is a mixed bag. Sure, platforms like Coinbase and Kraken make onboarding painless with clean interfaces and decent educational content, which helps if you’re still stuck on “blockchain” meaning Binance Academy for crypto knowledge