How do I crop the contents of an Iframe to show a part of a page?

Is there any way that I can crop the contents of the downloaded page to only show a section of that page on my website?

No. The Same Origin Policy prevents you from manipulating the iframe in any way, including the scroll position.

There would be a workaround by putting the iframe into an a div container that has a defined height and width, and overflow: hidden to clip the view port:

<div style="width: 500px; height: 500px; overflow: hidden">

and giving the iframe a relative position:

<iframe src="https://stackoverflow.com/questions/5676672/..." style="position: relative; left: -100px; top: -100px">

this way, you can adjust the portion of the iframe that is visible on the page. However, the whole page still gets rendered, and this approach is not immune to influences like scrolling inside the iframe.

Leave a Comment