Automatically Adjust IFrame Height According To Its Contents Using ...

TutorialRepublic HOME HTML5 CSS3 JAVASCRIPT JQUERY BOOTSTRAP5 v4.6 PHP7 SQL REFERENCES EXAMPLES FAQ SNIPPETS Online HTML Editor WEB TUTORIALS HTML Tutorial CSS Tutorial JavaScript Tutorial jQuery Tutorial Bootstrap Tutorial PHP Tutorial SQL Tutorial PRACTICE EXAMPLES HTML Examples CSS Examples JavaScript Examples jQuery Examples Bootstrap Examples PHP Examples HTML REFERENCES HTML Tags/Elements HTML Global Attributes HTML Event Attributes HTML Color Picker HTML Language Codes HTML Character Entities HTTP Status Codes CSS REFERENCES CSS At-rules CSS Properties CSS Animatable Properties CSS Color Values CSS Color Names CSS Web Safe Fonts CSS Aural Properties PHP REFERENCES PHP Array Functions PHP String Functions PHP File System Functions PHP Date/Time Functions PHP Calendar Functions PHP MySQLi Functions PHP Filters PHP Error Levels Automatically Adjust iFrame Height According to its Contents Using JavaScript

Topic: JavaScript / jQueryPrev|Next

Answer: Use the contentWindow Property

You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.

Let's try out the following example to understand how it really works:

Example

Try this code » <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Auto Adjust iFrame Height Based on Content</title> <style> iframe{ width: 100%; border: 2px solid #ccc; } </style> </head> <body> <iframe src="demo.php" id="myIframe"></iframe> <script> // Selecting the iframe element var iframe = document.getElementById("myIframe"); // Adjusting the iframe height onload event iframe.onload = function(){ iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px'; } </script> </body> </html>

Related FAQ

Here are some more FAQ related to this topic:

  • How to insert HTML content into an iFrame using jQuery
  • How to detect click inside iframe using JavaScript
  • How to animate a DIV height based on the content using jQuery
Previous Page Next Page Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties

Is this website helpful to you? Please give us a like, or share your feedback to help us improve. Connect with us on Facebook and Twitter for the latest updates.

About Us

Our Story Terms of Use Privacy Policy

Contact

Contact Us Report Error Advertise

Interactive Tools

Bootstrap Icon Search Utility HTML Formatter Title & Meta Length Calculator HTML Color Picker Bootstrap Button Generator SQL Playground Font Awesome Icon Finder HTML Editor

TutorialRepublic

BMC Copyright © 2024 Tutorial Republic. All Rights Reserved. Share This:

Từ khóa » Html Iframe Adjust Height To Content