2020-01-23
2990
Nada Rifki
12904
Jan 23, 2020 ⋅ 10 min read

The ultimate guide to iframes

Nada Rifki Nada is a JavaScript developer who likes to play with UI components to create interfaces with great UX. She specializes in Vue.js and loves sharing anything and everything that could help her fellow frontend web developers. Nada also dabbles in digital marketing, dance, and Chinese.

Recent posts:

Htmx Vs React

htmx vs. React: Choosing the right library for your project

Both htmx and React provide powerful tools for building web apps, but in different ways that are suited to different types of projects.

Temitope Oyedele
May 15, 2024 ⋅ 9 min read
Exploring The Top Pair Programming Tools

Exploring the top 5 pair programming tools

Review the top five pair programming tools, including how to use them, their features, drawbacks, pricing models, and more.

Elijah Asaolu
May 15, 2024 ⋅ 8 min read
Exploring Remix Vite And Other Breaking Changes In Version 2.2.0 And Version 2.7

Exploring Remix Vite support and other v2.20 and v7 changes

The Remix Vite integration helps speeds up development via features like HDR and HMR. Read about Remix Vite and other breaking changes.

Hussain Arif
May 14, 2024 ⋅ 7 min read
Caching In Next.js With Unstable_Cache

Caching in Next.js with unstable_cache

In this article, we explore the different caching strategies in Next.js, focusing on the `unstable_cache` function.

Kapeel Kokane
May 14, 2024 ⋅ 9 min read
View all posts

45 Replies to "The ultimate guide to iframes"

  1. Seamless attribute was removed from both W3C and WHATWG hrml specs, and implementation was removed from the browsers due to the security and other reasons https://caniuse.com/#feat=iframe-seamless

    Reply
  2. Missing guide: how to make iframe height automatically use it’s content height 🤔

    Reply
  3. Thank you for the information, I thought it was only experimental for the time being.

    Reply
  4. Hello Ariona, what do you mean exactly? 🙂

    Reply
  5. Nada, great art. Thanks. Just remove unnecessary “)” from postMessage link.

    Reply
    1. Nice catch. All set.

      Reply
  6. You talked nothing about “friendly iframe” when the iframe source is and that we do not need to send message events as those iframes can get all functionality from the parent window object…

    Reply
  7. Thank you, Nada, for this informative article! A helpful addition would be addressing accessibility issues with iframes.

    Reply
  8. There is a lot to be said about WCAG conformance an iframes. Technique H64: Using the title attribute of the frame and iframe elements ( https://www.w3.org/TR/WCAG20-TECHS/H64.html) addresses how this applies to WCAG Success Criteria 2.4.1 Bypass Blocks (level A) and 4.1.2 Name, Role, Value (level A). While conformance is more nuanced than a pass/fail, at least acknowledging the challenge and risk of being flagged by automated accessibility testing tools should be in this article.

    Reply
  9. I have a question.

    I’m using an iframe to load a media file. Click the link to the file and it loads into the named iframe.

    My link has a target=”media” attribute on it and the first video loads fine. However when I try to load the second video it will not load in the iframe, it loads in a new tab.

    Reply
  10. Just wondering how you got the google.com example to work. I get a “Blocked by X-Frame -Options Policy” for google, and “Blocked by Content Security Policy” for some other domains that I tried, But the Twitter button and the Logrocket examples work fine. I am using localhost/ 127.0.0.1 for testing, which might be the issue.

    Reply
  11. I have a lot of content on my site, and I recently implemented the use of (loading=”lazy”) to defer the loading of an iframe until the viewer opens the window. I noticed that it did not interfere with the laoding of the iframe content, however, the code was flagged as “not allowed” when validating my html. I also noticed that when using speed testing sites such as Google insights and GTMetrics, the browser is seeing and loading the content within the iframe even though I am using the lazy loading tag in the iframe?

    Reply
  12. Hi Don, can you tell me which browser (and version) you’re using ?

    Reply
  13. Hi, thanks for this guide, really interesting. You wrote “Because an iframe offers an isolated environment, this means that the focus or the selection is never lost when you are clicking outside of it.”
    I am actually facing a situation where my iFrame is losing its focus when clicking elsewhere… Any way to prevent that ?

    Reply
  14. Hi, thanks for this comprehensive iframe documentation , But frankly , I was looking for an answer to a difficult question , a question that no one online , even the Top Programming websites , could answer it till now ..
    This question is , how can we play a video game inside iframe , without the keyup or keydown forcing the whole page to scroll up or down , instead of focusing inside the iframe ?

    Reply
  15. Why don’t you simply disable the scroll when people are using the keyboard arrows? Something like https://stackoverflow.com/questions/8916620/disable-arrow-key-scrolling-in-users-browser

    Reply
  16. If you want to check when an iframe is not focused anymore, you can check this thread https://stackoverflow.com/questions/5456239/detecting-when-an-iframe-gets-or-loses-focus Then, you only have to refocus the iframe with javascript when it happens

    Reply
  17. Hi,
    Thanks for this excellent information with unique content and it is very useful to know about the information based on comprehensive iframe documentation.

    Reply
  18. Hi,

    Thanks for your guide! I tried to use it for error handling if the iFrame could not be loaded, but this does not seem to be possible, since the onerror event never gets triggered. Ans it also seems like (at least for Chrome), they are not going to fix that: https://bugs.chromium.org/p/chromium/issues/detail?id=365457

    Is there something im missing?

    Reply
  19. Thank you, Nada, for this informative article! A helpful addition would be addressing accessibility issues with iframes.

    Reply
  20. Any idea how to use IFRAME in windows application?

    Reply
  21. Yes , it worked that way . Thanks again .

    Reply
  22. thx Nada – I really like the overview quality of your article.
    if I integrate content via iFrame into a WP page is there a way I can avoid thrd parties to open the iFrame content without opening the complete page?

    Reply
  23. Can you please tell me how we can display a PDF file inside the iframe html element without download & print option in the frame window?

    Reply
  24. For some you can’t use external resources from iframe using a development server, especially when trying to fetch resources from Google. As a security measure google doesn’t allow that… hence a development server with a “localhost” in it’s domain is automatically blocked. There is a way to trick the system by changing your “localhost” domain or using https, I read somewhere tho I never actually tried it before just a friendly coder who stumbled on this article to learn more about iFrames.

    Reply
  25. Hello. Great post. I had a question about using iframe and jump links together. I am building a recipe site with a list of links to recipes from different sites. When the links are clicked the recipes are displayed within the iframe window at the top of the same page. I wanted to add jump links so the user to taken to the top of the page where the recipe is being displayed. Any suggestions?

    Reply
    1. set your target attibute: target=’_parent’

      Reply
  26. Great Article Nada – well done. I came to the sight to get some information on how cookies work within an iframe. I’m using .Net Core 2.2. and application (session) cookies are not being recognized in the same way as if the application runs outside the iframe. Any insight on cookie limitations and using sameSite=None/Lax/Strict (etc), and the meaning of these would be a great add to your article.

    Cheers!

    Reply
  27. im trying to add a iframe into elementor on wordpress and i cannot figure out to adjust the height, there is also a rule for scrolling in a an iframe i didnt see that here.

    Reply
  28. I wrote a set of pages a while ago. In fact last changed 2011! Now I am trying to resurrect them. But they were built around frameset(s) and frame(s) – I did write a kind of “file explorer”. I can work out what to change. But the main problems is how to move the iframe to be along the right, e.g. width=85% but I can’t see (in several different pages) how to have the iframe set right. I’ve seen talk of attribute object-position, but I can’t how to work it.

    Help!

    Reply
  29. nice guide. got the info, what im looking for.

    Reply
  30. I’ve done all I want, almost…(I worked out the rightside by using tables).

    Something like file explorer but with my photos across the world.

    I insert one (one of a number of pages) into the right side. On its own it’s fine, but inside an iframe, it does allow js. OK with variable but not OK with fumctions. I guess this tweaking some kind of attribute I need to use, but I can’t hack it.
    Help
    —–

    All I have to do after that is visibility:collapse

    And add or the places I travelled – mostly China / SE Asiia; and Europe. About 50000 photos, only about 1000 for this album.

    Reply
  31. it helped us a lot

    Reply
  32. How can I stop the refresh of iframe on button click or opening a pop up?

    Reply
  33. Great overview!

    Regarding security – please note that it’s considered unsecure to specify the origin domain as a wildcard (*) in your example – postMessage(‘message’, ‘*’).
    It’s best to be specific about the domains used for communications to prevent unwanted information discolusre/XSS attacks.

    I wrote a library that simplify communication between frames – it’s called iFramily ( https://github.com/EkoLabs/iframily).
    Basically it has a simpler API than postMessage, which includes Promise-based responses, message queuing, and managing the connection until both frames are ready to talk. It also takes a responsible approach to security…

    Would love to hear your thoughts!

    Reply
  34. Nice Nada,
    lazy load really help.
    I use it hundreds of times for images, It also works for iframe. LoL

    Reply
  35. I am planning to embed a third party survey url as a source to my modal window iframe. I want the user to take that survey only once and want to prevent view source or inspect element to show up the src somehow. Or at least want to make it obscure and unreadable. I tried setting it via JavaScript and I obfuscated the js setting this src but still after load of the iframe, src is viewable in plain text which earlier was set to unknown. Any help in securing the survey link?

    Reply
  36. @Nada Rifki
    Is there any way to get the text from click inside iframe.
    Explaination: I have an iframe on my page using window.getSelection() i get the selected text, similarly i want to get the selected text from iframe.
    Can we do that? if yes how?

    Reply
  37. Chris Coyier snippet is a really a good one, the white flash is not there any more.
    Thanks

    Reply
  38. Nice. Addressing accessibility concerns that are caused by iframes would be a valuable addition.

    Reply
  39. I found your article when searching for a solution to deal with my use case. Thank you for what I hope will be the solution!

    Reply
  40. After adding iframe the website speed shows slow. How can i optimize the iframe?

    Reply
  41. Hello, i want to open a link in two iframes. how its possible ?

    Reply
  42. This guide was very helpful for me

    Reply
  43. I have tried https://github.com/EkoLabs/iframily and https://github.com/SpringRoll/Bellhop. Finally I choose Bellhop over iframily

    Reply

Leave a Reply Cancel reply

两个鬼故事起名字的方法戴姆勒大厦布雷斯塔警长国语根据父母名称起名字继电器延时电路牛奶超市店铺起名孩子生辰八字起名小餐厅起个什么名字姓贾女孩起名字啊吉号吧电视剧平原烽火全集产品起名网站免费取名草字头字旁的字男孩起名字药店起名字大全免费起名字男孩晋字王姓男孩起名100分为奇葩的起名武侠小说排行榜完本免费的公司起名网站青玉案贺铸bl动漫推荐门窗安装公司名字起名大全注册公司免费起名软件妈妈的朋友2在线观看成语寓意好的起名字好听三点水起名字带睿字的起名字宝宝起名女孩小名好北京体育频道鞠敬伟少年生前被连续抽血16次?多部门介入两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”淀粉肠小王子日销售额涨超10倍高中生被打伤下体休学 邯郸通报单亲妈妈陷入热恋 14岁儿子报警何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言张家界的山上“长”满了韩国人?男孩8年未见母亲被告知被遗忘中国拥有亿元资产的家庭达13.3万户19岁小伙救下5人后溺亡 多方发声315晚会后胖东来又人满为患了张立群任西安交通大学校长“重生之我在北大当嫡校长”男子被猫抓伤后确诊“猫抓病”测试车高速逃费 小米:已补缴周杰伦一审败诉网易网友洛杉矶偶遇贾玲今日春分倪萍分享减重40斤方法七年后宇文玥被薅头发捞上岸许家印被限制高消费萧美琴窜访捷克 外交部回应联合利华开始重组专访95后高颜值猪保姆胖东来员工每周单休无小长假男子被流浪猫绊倒 投喂者赔24万小米汽车超级工厂正式揭幕黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发当地回应沈阳致3死车祸车主疑毒驾恒大被罚41.75亿到底怎么缴妈妈回应孩子在校撞护栏坠楼外国人感慨凌晨的中国很安全杨倩无缘巴黎奥运校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变王树国卸任西安交大校长 师生送别手机成瘾是影响睡眠质量重要因素国产伟哥去年销售近13亿阿根廷将发行1万与2万面值的纸币兔狲“狲大娘”因病死亡遭遇山火的松茸之乡“开封王婆”爆火:促成四五十对奥巴马现身唐宁街 黑色着装引猜测考生莫言也上北大硕士复试名单了德国打算提及普京时仅用姓名天水麻辣烫把捣辣椒大爷累坏了

两个鬼故事 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化