Automatically Adjust IFrame Height According To Its Contents Using ...
Có thể bạn quan tâm
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
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 PolicyContact
Contact Us Report Error AdvertiseInteractive Tools
Bootstrap Icon Search Utility HTML Formatter Title & Meta Length Calculator HTML Color Picker Bootstrap Button Generator SQL Playground Font Awesome Icon Finder HTML EditorCopyright © 2024 Tutorial Republic. All Rights Reserved. Share This:
Từ khóa » Html Iframe Adjust Height To Content
-
Make Iframe Automatically Adjust Height According To The Contents ...
-
How To Adjust The Width And Height Of Iframe To Fit With Content In It
-
Adjust IFrame Height According To Its Contents Code Example
-
Change Iframe Size Automatically To Fit Content & Prevent Scrollbars
-
Auto-resize Iframe When Content Size Changes - WillMaster
-
Iframe Auto Adjust Height As Content Changes
-
HTML DOM IFrame Height Property - W3Schools
-
HTML Iframe Height Attribute - W3Schools
-
Resize Iframe To Fit Content (Same Domain Only) - CSS-Tricks
-
How To Adjust Width And Height Of Iframe To Fit With Content In It
-
Auto Adjust HTML IFrame Height According To Page Contents JS
-
How To Automatically Resize An Iframe | By Bret Cameron
-
3 Ways To Resize IFrames In HTML - WikiHow
-
Auto Adjust Height Of Iframe Based On Content - Mobirise Forums