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.
Психотерапевт Оренбург. Кпт курган. 385 оценок
Психотерапевт Челны. batmanapollo.ru 754 оценок
Психотерапевты Самара. batmanapollo.ru 458 оценок
Кпт курган. batmanapollo.ru 287 оценок
Психотерапевт Белгород. batmanapollo.ru 568 оценок
Б17 психологи. Психолог 430 573 оценок
В17 психология. Психолог 601 936 оценок
Психотерапевт Белгород. professorkorotkov.ru 178 оценок
В17 психология. professorkorotkov.ru 566 оценок
Психотерапевт Белгород. chat-s-psikhologom-v-telegramme.ru 616 оценок
Психотерапевт Челны. chat-s-psikhologom-v-telegramme.ru 160 оценок
Б17 психологи. chat-s-psikhologom-v-telegramme.ru 962 оценок
Психотерапевт Челны. Психотерапевт онлайн 416 оценок
Психотерапевты Самара. Психолог онлайн 231 оценок
На прием Клинцы. Психотерапевт онлайн 601 оценок
В17 психология. Психотерапевт онлайн 458 оценок
Психотерапевт Челны. Психолог онлайн 298 оценок
Б17 психологи. Психолог онлайн 656 оценок
На прием Клинцы. Психотерапевт онлайн 683 оценок
Психотерапевт Челны. Психотерапевт онлайн 163 оценок
Как сложить бюстгальтер в чемодан Как сложить вещи в чемодан. 624 благодарностей
Как сложить бюстгальтер в чемодан Как сложить вещи в чемодан в самолет 975 благодарностей
https://t.me/s/TopTg777_KENT
https://t.me/s/TopTg777_Monro
Упаковать чемодан компактно Как складывать вещи в чемодан чтобы они не мялись 760 благодарностей
Психолог оценили 4692 раз
Психолог оценили 6183 раз
Дизайн человека 20 46 52 Ворота Дизайн человека 35 Ворота Дизайн человека 57 Ворота Дизайн человека 20 Ворота Дизайн человека 51 Ворота Дизайн человека 61 Ворота Дизайн человека 58 Ворота Дизайн человека 5 Ворота Дизайн человека 14 Ворота Дизайн человека 59 Ворота Дизайн человека 44 Ворота Дизайн человека
Дизайн человека 43 53 18 Ворота Дизайн человека 10 Ворота Дизайн человека 57 Ворота Дизайн человека 36 Ворота Дизайн человека 37 Ворота Дизайн человека 54 Ворота Дизайн человека 44 Ворота Дизайн человека 19 Ворота Дизайн человека 54 Ворота Дизайн человека 40 Ворота Дизайн человека 3 Ворота Дизайн человека
Hi there! I know this is kinda off topic but I was
wondering which blog platform are you using for this website?
I’m getting fed up of WordPress because I’ve had issues with hackers
and I’m looking at options for another platform.
I would be fantastic if you could point me in the direction of a good platform.
Дизайн человека 16 37 47 Ворота Дизайн человека 10 Ворота Дизайн человека 49 Ворота Дизайн человека 29 Ворота Дизайн человека 54 Ворота Дизайн человека 51 Ворота Дизайн человека 62 Ворота Дизайн человека 60 Ворота Дизайн человека 4 Ворота Дизайн человека 59 Ворота Дизайн человека 45 Ворота Дизайн человека
Психолог 16 50
Психолог 60 15
Психолог 37 36
Психолог 25 25
Психолог 20 7
Психолог 30 58
https://t.me/s/Web_1win
1вин вход 1win
Hi this is kinda of off topic but I was wanting to know if blogs use WYSIWYG
editors or if you have to manually code with HTML.
I’m starting a blog soon but have no coding expertise so
I wanted to get guidance from someone with experience.
Any help would be greatly appreciated!
For hottest information you have to go to see web and on internet I found this site as a finest site for most up-to-date updates.
Wow, this paragraph is nice, my younger sister is analyzing these kinds of things, thus I am going
to tell her.
Fastidious response in return of this question with genuine arguments and telling the
whole thing regarding that.
Every weekend i used to go to see this website, for the
reason that i wish for enjoyment, since this
this web page conations genuinely good funny material too.
Hello my friend! I wish to say that this article is
amazing, great written and include almost all significant infos.
I’d like to look more posts like this .
Wow! This blog looks exactly like my old one!
It’s on a completely different subject but it has pretty much the
same page layout and design. Superb choice of colors!
https://t.me/s/Official_1win_kanal/1148
I like the helpful info you provide in your articles.
I’ll bookmark your blog and check again here frequently. I’m
quite sure I’ll learn lots of new stuff right here! Good luck
for the next!
https://t.me/s/Webs_1WIN
Wow, fantastic blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your website is wonderful, let alone the content!