{"id":31,"date":"2019-07-22T07:45:35","date_gmt":"2019-07-22T07:45:35","guid":{"rendered":"http:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/"},"modified":"2019-07-22T07:45:35","modified_gmt":"2019-07-22T07:45:35","slug":"create-dynamic-iframe-with-auto-height","status":"publish","type":"post","link":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/","title":{"rendered":"Create dynamic iframe with auto height"},"content":{"rendered":"<p>Sometimes we need to create an dynamic iframe with height auto init. I will put a code to create a dynamic iframe inside a modal and add the code to auto height for iframe and modal.<\/p>\n<pre><code>var doc = document.getElementById('iframe_messages').contentWindow.document;\n\tdoc.open();\n\tdoc.innerHTML = \"\";\n\tdoc.write(message);\n\tdoc.close();\n\t$(\"#emailContentModal\").modal({\n\t\tshow: true\n\t});\n\t$(\"#emailContentModal .modal-body\").css(\"height\", \"\")\n\t$(\"#iframe_messages\").css(\"height\", \"\")\n\t$('#emailContentModal').on('shown.bs.modal', function () {\n\t\tvar messageHeight = $('#iframe_messages').contents().find('html').height();\n\t\tvar iframeHeight = $('#iframe_messages').height();\n\t\tif(iframeHeight &lt; messageHeight) {\n\t\t\t$('#iframe_messages').height(messageHeight);\n\t\t\t$(\"#emailContentModal .modal-body\").height(messageHeight + 100)\n\t\t}\n\t})<\/code><\/pre>\n<pre><code>&lt;div class=\"modal fade emailpp\" id=\"emailContentModal\" role=\"dialog\"&gt;\n    &lt;div class=\"modal-dialog\"&gt;\n        &lt;div class=\"modal-content\"&gt;\n            &lt;div class=\"modal-header\"&gt;\n                &lt;button type=\"button\" class=\"close\" data-dismiss=\"modal\"&gt;\u00d7&lt;\/button&gt;\n                &lt;h4 class=\"modal-title\"&gt;Email Message &lt;\/h4&gt;\n            &lt;\/div&gt;\n            &lt;div class=\"modal-body\"&gt;\n                &lt;div id=\"email_body_content\"&gt;\n                    &lt;h4&gt;&lt;span class=\"normal\"&gt;Recipient:&lt;\/span&gt; &lt;span id=\"receipt_email\"&gt;&lt;\/span&gt;&lt;\/h4&gt;\n                    &lt;h5&gt;Subject: &lt;span id=\"subjec_email\"&gt;&lt;\/span&gt;&lt;\/h5&gt;\n                    &lt;iframe id=\"iframe_messages\" class=\"iframes_emails\" height=\"600px\" width=\"700px\" src=\"about:blank\"&gt;&lt;\/iframe&gt;\n                &lt;\/div&gt;\n                &lt;!-- \/#email_body_content --&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we need to create an dynamic iframe with height auto init. I will put a code to create a dynamic iframe inside a modal and add the code to auto height for iframe and modal. var doc = document.getElementById(&#8216;iframe_messages&#8217;).contentWindow.document; doc.open(); doc.innerHTML = &#8220;&#8221;; doc.write(message); doc.close(); $(&#8220;#emailContentModal&#8221;).modal({ show: true }); $(&#8220;#emailContentModal .modal-body&#8221;).css(&#8220;height&#8221;, &#8220;&#8221;) $(&#8220;#iframe_messages&#8221;).css(&#8220;height&#8221;, &#8220;&#8221;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create dynamic iframe with auto height - Santosh Kumar Shah<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create dynamic iframe with auto height - Santosh Kumar Shah\" \/>\n<meta property=\"og:description\" content=\"Sometimes we need to create an dynamic iframe with height auto init. I will put a code to create a dynamic iframe inside a modal and add the code to auto height for iframe and modal. var doc = document.getElementById(&#039;iframe_messages&#039;).contentWindow.document; doc.open(); doc.innerHTML = &quot;&quot;; doc.write(message); doc.close(); $(&quot;#emailContentModal&quot;).modal({ show: true }); $(&quot;#emailContentModal .modal-body&quot;).css(&quot;height&quot;, &quot;&quot;) $(&quot;#iframe_messages&quot;).css(&quot;height&quot;, &quot;&quot;) [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/\" \/>\n<meta property=\"og:site_name\" content=\"Santosh Kumar Shah\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-22T07:45:35+00:00\" \/>\n<meta name=\"author\" content=\"Santosh Kumar Shah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Santosh Kumar Shah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/\",\"url\":\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/\",\"name\":\"Create dynamic iframe with auto height - Santosh Kumar Shah\",\"isPartOf\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\"},\"datePublished\":\"2019-07-22T07:45:35+00:00\",\"author\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\"},\"breadcrumb\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/santosh-shah.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create dynamic iframe with auto height\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\",\"url\":\"https:\/\/santosh-shah.com\/blog\/\",\"name\":\"Santosh Kumar Shah\",\"description\":\"JavaScript Developer\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\",\"name\":\"Santosh Kumar Shah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"caption\":\"Santosh Kumar Shah\"},\"description\":\"I am JavaScript developer.\",\"sameAs\":[\"https:\/\/santosh-shah.com\/blog\"],\"url\":\"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create dynamic iframe with auto height - Santosh Kumar Shah","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/","og_locale":"en_US","og_type":"article","og_title":"Create dynamic iframe with auto height - Santosh Kumar Shah","og_description":"Sometimes we need to create an dynamic iframe with height auto init. I will put a code to create a dynamic iframe inside a modal and add the code to auto height for iframe and modal. var doc = document.getElementById('iframe_messages').contentWindow.document; doc.open(); doc.innerHTML = \"\"; doc.write(message); doc.close(); $(\"#emailContentModal\").modal({ show: true }); $(\"#emailContentModal .modal-body\").css(\"height\", \"\") $(\"#iframe_messages\").css(\"height\", \"\") [&hellip;]","og_url":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/","og_site_name":"Santosh Kumar Shah","article_published_time":"2019-07-22T07:45:35+00:00","author":"Santosh Kumar Shah","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Santosh Kumar Shah","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/","url":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/","name":"Create dynamic iframe with auto height - Santosh Kumar Shah","isPartOf":{"@id":"https:\/\/santosh-shah.com\/blog\/#website"},"datePublished":"2019-07-22T07:45:35+00:00","author":{"@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f"},"breadcrumb":{"@id":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/santosh-shah.com\/blog\/create-dynamic-iframe-with-auto-height\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/santosh-shah.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create dynamic iframe with auto height"}]},{"@type":"WebSite","@id":"https:\/\/santosh-shah.com\/blog\/#website","url":"https:\/\/santosh-shah.com\/blog\/","name":"Santosh Kumar Shah","description":"JavaScript Developer","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f","name":"Santosh Kumar Shah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","caption":"Santosh Kumar Shah"},"description":"I am JavaScript developer.","sameAs":["https:\/\/santosh-shah.com\/blog"],"url":"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/"}]}},"_links":{"self":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":0,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"wp:attachment":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}