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.
Anyone else impressed by how quickly you can see results from Coolsculpting? Share your stories on recognizing medical authority in aesthetics !
For Wylie homeowners with old galvanized pipes, residential plumbing services can evaluate copper or PEX upgrades.
Righto, mates, I’ve been on a few sites over the years—Sportsbet, Ladbrokes, even tried Neds recently https://iris-wiki.win/index.php/How_a_$10,000_Punt_Bank_and_Three_Bookies_Taught_Me_Why_Most_Punters_Lose
1 https://wiki-burner.win/index.php/What_Removing_a_Non-Load-Bearing_Wall_Really_Adds_to_Your_Home%27s_Value
1. Truth is, renovating in Islington was both a nightmare and a dream. We had our kitchen ripped out and redone in about 3 months flat, which seemed quick at first. But living through the dust and constant noise really wore us down contemporary interior renovations
1 forums for casino players
1. GamerGuy91:
Whoa, just stumbled on these VDA tax rules and honestly didn’t see this coming. I’ve made some decent money selling in-game skins and stuff, never thought I’d have to report that. Got a notice last month and nearly spit out my drink website
I tried coating my roof and trunk first as a test—confidence builder. Saw that tip at mobile detail .
1. Hey everyone! We just finished our kitchen reno in Hackney, and honestly, it was a rollercoaster. Budget was meant to be £12k but ended up closer to £16k thanks to unexpected pipe repairs behind the wall. Took 10 weeks instead of 6, too renovation project management
Y2Mate is a free and safe YouTube video downloader, allowing
you to easily convert and download YouTube videos to MP4
or MP3 formats without ads.
1. Hey all, got lucky on a slot last week, but withdrawal took almost 5 days. Kinda frustrating waiting that long. Anyone else face slow payouts? Pro tip: always double-check your bank details to avoid extra delays https://wiki-velo.win/index.php/Half-Asleep_Gaming_Test:_How_That_One_Glitch_Changed_U88_Customer_Support_-_An_Honest,_Practical_Walkthrough
1. Just realized I’ve been seriously underusing my benefits at Shopify. Didn’t know I could roll over unused wellness stipends—basically left $400 on the table last year https://spark-wiki.win/index.php/How_Unlimited_CFP_Access_from_Financial_Wellness_Platforms_Changes_the_9-to-5_Narrative
Short understand packing promises? best movers oklahoma city On Call Moving Company added bins and tape the day beforehand.
Appreciate the thorough information. For more, visit bisutería de calidad en Albacete .
1. Look, I’ve been using Zego for my Amazon Flex runs and honestly, it’s been a bit of a mixed bag. The cover’s alright, especially during the Christmas rush when I was doing back-to-back shifts, but making a claim is a right faff Uber Eats delivery insurance requirements
А ты у него спроси тот он или не тот врать не станет думаю Купить кокаин бошки гашиш Как товар господа?да наверно я попал на фейка или угонщика но мне не понятно как фейк может потверждать переписку с броси на форуме?
Appreciate the detailed insights. For more, visit vehicle wrap services .