-1

Please excuse me if this has been answered elsewhere, I couldn't find the answer to my exact query, hence this post. I have a website created in pure HTML and CSS, with use of Javascript and jQuery for styling features. However, the website doesn't have a CMS for back-end. It's a somewhat simple website.

However, I am using a PHP script in order to run a mini e-commerce store. The storefront is very simple, it has products, and a simple checkout. The storefront does not have any header, footer or anything else. And this storefront is located fully in a sub-directory (e.g. /store/index.php).

Now, I want to use an iFrame to put the /store/index.php page into the body of my /store.html page, as this has a coherent header and footer, meta tags etc.

When I insert the iFrame into the html page, I make the width 100% and that is fine, because both the html page and the storefront are responsive.

However, when I access the site using a mobile device - or - when I click on a product with a long description, the source-page becomes 'longer' than the height of the iFrame and therefore, scrollbars appear. This is problematic because there are now two scrollbars on the page, and it gets messy when using a mobile device.

Is there any way that I and iFrame's height can be dynamic, dependant on the height of the page it is linked to (the source page) - not just on-page-load, but actually dynamic in real time?

The only other way will be to build a similar header and footer on the storefront, and this will be a long and difficult process as both the front-end and storefront have been built using different CSS sheets etc.

Thanks :-)

Dr HY
  • 101
  • 7
  • have you tried using javascript to get the required height from the DOM and apply it to the iframe? – SierraOscar Feb 19 '20 at 16:18
  • I have tried a few scripts I found that were javascript, but none of them seemed to be dynamic and change (perpetually and constantly) as per the height of content in source changing... – Dr HY Feb 19 '20 at 16:21
  • ok, so can you update your question with what you _have_ tried. Javascript and jQuery are very capable of achieving what you want as they are predominantly event driven - and you're after something that changes based on an event. – SierraOscar Feb 19 '20 at 16:31
  • 1
    Already answered [here](https://stackoverflow.com/questions/9162933/make-iframe-height-dynamic-based-on-content-inside-jquery-javascript) – Indrajeet Patil Feb 19 '20 at 16:49

1 Answers1

0

Have you tried setting the iFrame's size in viewport height and width instead of a percentage? This would make it more dynamic than saying width='100%' considering that percentage is whatever size the parent element would be, where as vh and vw would be looking at the size of the viewport instead of the element.

sams
  • 23
  • 5