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 Size To Fit Content
-
Adjust Width And Height Of Iframe To Fit With Content In It - Stack Overflow
-
How To Adjust The Width And Height Of Iframe To Fit With Content In It
-
Change Iframe Size Automatically To Fit Content & Prevent Scrollbars
-
Resize Iframe To Fit Content (Same Domain Only) - CSS-Tricks
-
How To Scale The Content Of
-
How To Adjust Width And Height Of Iframe To Fit With Content In It
-
How Do I Fit An Iframe To Its Size? - Brain Writings
-
Iframe Height 100 Code Example
-
Resize External Website Content To Fit Iframe Width
-
Iframe Width Of Parent Code Example - Code Grepper
-
Adjust The IFrame Height To Fit With Content In JavaScript - StackHowTo
-
Iframe Auto Adjust Height As Content Changes
-
3 Ways To Resize IFrames In HTML - WikiHow
-
How To Create Responsive Iframes - W3Schools